Results 1 to 4 of 4

Thread: How do I simulate mouse clicks?

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2001
    Location
    Connecticut
    Posts
    4

    How do I simulate mouse clicks?

    I posted this in the "general questions" forum and someone mentioned Mouse_Events and said I should post this question here. I must admit though, I've never used API (that I know of anyway), and the VB Help file seems to be telling me that I can only use MouseEvents with Visual C++, which I quess would be ok, but I've never used visual C, though have used C extensivly in the past (borland).


    I want a VB program to take over the mouse. what I really need is to press my mouse button every 10 seconds until I stop the program. I want to physicaly move the mouse myself, but I want the mouse to press the left button automaticaly. It almost seems like this type of program would have been writen already so if you know of a program let me know. if not, does anyone know how to do this? the mouse cursor would not be over a VB form, it could be anywhere on the screen.

    Thanks

  2. #2
    Megatron
    Guest
    Add this to the General Declarations section of the Form.
    VB Code:
    1. Private Type POINTAPI
    2.     x As Long
    3.     y As Long
    4. End Type
    5. Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    6. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    7. Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
    8. Private Const WM_LBUTTONDOWN = &H201
    9. Private Const WM_LBUTTONUP = &H202
    Add a Timer to the Form, and set it's Interval to 10, then add the following code to it.
    VB Code:
    1. Dim hWin As Long
    2. Dim PT As POINTAPI
    3.  
    4. GetCursorPos PT
    5. hWin = WindowFromPoint(PT.x, PT.y)
    6. If hWin Then
    7.     PostMessage hWin, WM_LBUTTONDOWN, 1, 0
    8.     PostMessage hWin, WM_LBUTTONUP, 1, 0
    9. End If

  3. #3
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    if you set the timer interval to 10, that code will execute every ten miliseconds, not every ten seconds.

    I'd suggest using a Do...Loop method (you the timer function)

  4. #4
    Megatron
    Guest
    Oops. Sorry about that.

    Change the interval to 10000 instead of 10.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width