• Welcome to Valhalla Legends Archive.
 

Input mouse clicks into a running program

Started by Fr0z3N, February 01, 2006, 04:34 PM

Previous topic - Next topic

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.

l2k-Shadow

well you can always use SendMessage.
If that's not what you're looking for try SetCursorPos and mouse_event.
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

Fr0z3N

#2
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.

FrOzeN

#3
Declare:
Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long

Usage:
SetCursorPos X, Y

If you want to move it to a certain location on another app, assuming you have that application's hWnd you can do:

Declares:
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


Usage:
Dim lpPoint As POINTAPI
lpPoint.X = egX
lpPoint.Y = egY
ClientToScreen eghWnd, lpPoint
SetCursorPos lpPoint.X, lpPoint.Y

(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.

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

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.
~ FrOzeN