Author | Message | Time |
---|---|---|
Fr0z3N | What I wanna do is input mouseclicks into a program I've hooked into, I have no idea how to do this or what api to use. So any tips are appreciated. | February 1, 2006, 10:34 PM |
l2k-Shadow | well you can always use SendMessage. If that's not what you're looking for try SetCursorPos and mouse_event. | February 1, 2006, 11:41 PM |
Fr0z3N | Yeah I'm trying to use the SendMessage API but I don't know how to send in the co-ordinates of where I wanna click. The thing I'm stumpted on is what to send for lParam, you need the send the co-ordinates but I dunno how.. I've tryed X and Y, X & Y, X & " " & Y, tryed putting them in a type and a few other things. | February 2, 2006, 4:44 AM |
FrOzeN | Declare: [code]Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long[/code] Usage: [code]SetCursorPos X, Y[/code] If you want to move it to a certain location on another app, assuming you have that application's hWnd you can do: Declares: [code]Private Type POINTAPI X As Long Y As Long End Type Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long Private Declare Function ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long[/code] Usage: [code]Dim lpPoint As POINTAPI lpPoint.X = egX lpPoint.Y = egY ClientToScreen eghWnd, lpPoint SetCursorPos lpPoint.X, lpPoint.Y[/code] (Replacing egX with Left, egY with Top and eghWnd with the application's hWnd.) Hope that helps. :) Not too sure about sending mouse clicks. [EDIT] Oops, didn't read post above correctly so you probably already know this, though, the ClientToScreen might be handy if your simulating your events on another program. [EDIT 2] I was just mucking around with the mouse_event thingy l2k-Shadow said. With the following code I was able to make it click my winamp play button. Maybe with some modifying you'll be able to get it working for you. [code]Option Explicit Private Type POINTAPI X As Long Y As Long End Type Private Const MOUSEEVENTF_ABSOLUTE = &H8000 Private Const MOUSEEVENTF_LEFTDOWN = &H2 Private Const MOUSEEVENTF_LEFTUP = &H4 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) Private Sub Form_Load() Dim hWnd_Winamp As Long hWnd_Winamp = FindWindow("Winamp v1.x", vbNullString) If hWnd_Winamp <> 0 Then Dim lpPoint As POINTAPI lpPoint.X = 50 lpPoint.Y = 90 ClientToScreen hWnd_Winamp, lpPoint SetCursorPos lpPoint.X, lpPoint.Y mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_ABSOLUTE, 50, 90, 0, 0 mouse_event MOUSEEVENTF_LEFTUP Or MOUSEEVENTF_ABSOLUTE, 0, 0, 0, 0 End If End Sub[/code] The downside was that Winamp had to be the Topmost program. If it was minimized or had a program infront of it then it would just send a LeftClick to the co-ordinates 0, 0 on my screen. | February 2, 2006, 6:44 AM |