PDA

Click to See Complete Forum and Search --> : Mouse automatically click?


danyal711
Nov 5th, 1999, 09:32 AM
How can i get the mouse to automatically click???? Like on its own

Aaron Young
Nov 5th, 1999, 09:44 AM
Use the Mouse_Event API, eg.

Private Type POINTAPI
x As Long
y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) 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 Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4

Private Sub Command1_Click()
Dim tPoint As POINTAPI
Call GetCursorPos(tPoint)
Call mouse_event(MOUSEEVENTF_LEFTDOWN, tPoint.x, tPoint.y, 0, 0)
Call mouse_event(MOUSEEVENTF_LEFTUP, tPoint.x, tPoint.y, 0, 0)
End Sub


------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

Yonatan
Nov 5th, 1999, 05:51 PM
Two comments.
1. You don't need to specify the dx and dy if the dwFlags doesn't include MOUSEEVENTF_ABSOLUTE. If you don't include it, the mouse_event procedure will move the cursor dx pixels to the right and dy pixels down. (0, 0) means don't move it at all.

2. You can click in one call, by combining MOUSEEVENTF_LEFTDOWN with MOUSEEVENTF_LEFTUP (&H2 Or &H4 = &H6).

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 Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4


Private Sub Command1_Click()
Call mouse_event(MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
End Sub


------------------
Yonatan
Teenage Programmer
E-Mail: RZvika@netvision.net.il
ICQ: 19552879 (http://www.icq.com/19552879)

[This message has been edited by Yonatan (edited 11-06-1999).]