Results 1 to 9 of 9

Thread: [RESOLVED] Make the mouse click

  1. #1

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Resolved [RESOLVED] Make the mouse click

    How do i make the mouse click by typing like Mouse.click.do if you get what i mean.

    BEcause i need it to go to a position onscreen and click.

    Also how would i do rightclick?

  2. #2

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Make the mouse click

    you can use the mouse_event api to simulate left or right mouseclicks:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Declare Sub SetCursorPos Lib "User32" (ByVal X As Integer, ByVal Y As Integer)
    4.     Private Const MOUSEEVENTF_LEFTDOWN As Integer = &H2
    5.     Private Const MOUSEEVENTF_LEFTUP As Integer = &H4
    6.     Private Const MOUSEEVENTF_RIGHTDOWN As Integer = &H6
    7.     Private Const MOUSEEVENTF_RIGHTUP As Integer = &H8
    8.     Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Integer, _
    9.                                                   ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
    10.  
    11.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    12.         MsgBox("you clicked")
    13.     End Sub
    14.  
    15.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    16.         Dim p As Point = Button1.PointToScreen(New Point(1, 1))
    17.         SetCursorPos(p.X, p.Y)
    18.         mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    19.         mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    20.     End Sub
    21.  
    22. End Class

  4. #4

  5. #5

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Re: [RESOLVED] Make the mouse click

    in the end i used this code
    VB.NET Code:
    1. Private Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As IntPtr)
    2.     Const MOUSEEVENTF_LEFTDOWN As Integer = 2
    3.     Const MOUSEEVENTF_LEFTUP As Integer = 4
    4.     Const MOUSEEVENTF_RIGHTDOWN As Integer = 6
    5.     Const MOUSEEVENTF_RIGHTUP As Integer = 8
    6.  
    7.  
    8.     mouse_event(MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0, 0, 0, IntPtr.Zero)

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [RESOLVED] Make the mouse click

    Quote Originally Posted by Emcrank View Post
    in the end i used this code
    VB.NET Code:
    1. Private Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As IntPtr)
    2.     Const MOUSEEVENTF_LEFTDOWN As Integer = 2
    3.     Const MOUSEEVENTF_LEFTUP As Integer = 4
    4.     Const MOUSEEVENTF_RIGHTDOWN As Integer = 6
    5.     Const MOUSEEVENTF_RIGHTUP As Integer = 8
    6.  
    7.  
    8.     mouse_event(MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0, 0, 0, IntPtr.Zero)
    that's not the way to do it. it could cause problems with your OS if you don't use it correctly, i.e. a MOUSEEVENTF_LEFTUP after a MOUSEEVENTF_LEFTDOWN + not combined

  7. #7

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Re: [RESOLVED] Make the mouse click

    What do you mean?
    EDIT: Oh do you mean i need to do????
    Code:
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, IntPtr.Zero)
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, IntPtr.Zero)
    Instead of both in the same mouse_event
    Code:
    mouse_event(MOUSEEVENTF_LEFTDOWN + MOUSEEVENTF_LEFTUP, 0, 0, 0, IntPtr.Zero)
    Correct me if im wrong

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [RESOLVED] Make the mouse click

    you're right

  9. #9

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