Is there any way to autoclick with the mouse?

Hi. It's me again. I was wondering, (and I'll probably get a simple answer that I could've figured out on my own.) is there any way to make the mouse move to a certain point on the screen, and then click by itself Thanks.


Answer this question

Is there any way to autoclick with the mouse?

  • jchau

    This thread shows a program that displays the mouse cursor position, even if it is located over another app's window. Note that this is almost certainly not what you want, a window could be located anywhere, depending on the position of the window frame. Search the forums for "FindWindow" and "EnumChildWindows". Also, learn how to use Spy++ to discover window properties.


  • yadgor2000

    You don't physically have to mouse the mouse, just generate the messages as though the mouse was clicked. The sample program below demonstrates the technique, it locates the window to be clicked from the screen location, then sends the mouse down and mouse up messages. It works with external apps too, as long as you know where the window is located and the window is visible on the desktop.

    Public Class Form1
    Private Declare Auto Function WindowFromPoint Lib "user32.dll" (ByVal pnt As Point) As IntPtr
    Private Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wp As IntPtr, ByVal lp As IntPtr) As Integer
    Private Const WM_LBUTTONDOWN As Integer = &H201
    Private Const WM_LBUTTONUP As Integer = &H202

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim pnt As Point = Me.PointToScreen(Button2.Location)
    Dim hWnd As IntPtr = WindowFromPoint(pnt)
    If hWnd <> IntPtr.Zero Then
    SendMessage(hWnd, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero)
    SendMessage(hWnd, WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero)
    End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    MsgBox("Click!")
    End Sub
    End Class



  • bozo14

    Thanks!
  • Jeanne P

    Thanks everyone, but I need to know the mouse coordinates for when I'm developing the program, not running it. Like, if I wanted to click the mouse at 100,100 on the screen, and I wanted to know what would be there, I would minimize VB 2005 and open that program, and it'll tell me where the mouse is. Not when MY program is running, but when I'm developing the program. Let's say there's a button my program will click, but I need to know where that button is so I can enter the X,Y coordinates into my program. I need something like that, something that will tell me where the mouse is so I can put those coordinates into my program.

  • Mach1

    I need to create a program that will be able to retrieve data from a gaming software. Such as card values for 5 cards on the screen in another program. I noticed you put up a nice procedure on how to make autoclicks on other programs and just thought you could explain how to retrieve data from another program.

  • Tiago Gerard Machado

    indeed!

    Cursor.Position = new Point(x, y)

    which sets the cursor position to anywhere on the screen you specify

    in regards to mouse click, P/Invoke would be in order here:

    //declare global:

    const MOUSEEVENTF_LEFTDOWN As UInt32 = &H2

    const MOUSEEVENTF_LEFTUP As UInt32 = &H4

    <DllImport("user32.dll", SetLastError:=true)> public shared function mouse_event(byval dwFlags as UInt32, byval dx as Uint32, byval dy as Uint32, byval dwData as uint32, byval dwExtraInfo as IntPtr) as Integer

    end function

    then to access it (clicking):

    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new IntPtr()) 'left down

    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, new IntPtr()) 'left Up

    does this help



  • Muhsin Zahid U&amp;#287;ur

    You can do a small program with a timer and use the Cursor.ToString() to change the text of your form every 10mseconds.

    Then use the mouse to go to the button you need to know its coordinates then record the coordinates.

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    Me.Text = Cursor.Position.ToString()

    End Sub

    You can use it to decide where your next program should click

    Best Regards and Good Luck,

    Amr Ouf



  • Prashant_Rai

    Cursor.Position has everything you need, adding a ToString() tells you the co-ordinates of the mouse where it currently is on the screen.

  • nikoo

    hello i need to have my computer make autoclicks ( mouse click) without me actually at the computer. I want to be able to leave my computer and have my computer make mouse clicks in a program while I am away from the computer for a period of time. I am sort of familiar with a program called winscrape that recognizes buttons in a poker software a allows you to relate to those values in a way. I am not wanting to do this for a poker software but something similar. I need to know how to make a formula that will calculate a solution with input from images from the software and then make the proper mouse click in the software according to the proper solution.



  • S Tonstad

    I have a related question. I want to send the X coordinate of the mouse to one variable; and the Y coordinate of the mouse to another variable. Preferably, they shouldn't be in screen coordinates (is it called client coordinates ) Here is my code so far:

    'Dim FullCo As 'System.Drawing.Point

    Dim NIntXCo, NIntYCo As System.Drawing.Point

    Dim XCo, YCo As Integer 'clicked coordinates

    Private Sub FrmTic_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick

    'FullCo = Location 'New Point(Location)

    'XCo = Location.X

    'YCo = Location.Y

    NIntXCo = Windows.Forms.Cursor.Position

    NIntYCo = Windows.Forms.Cursor.Position

    XCo = CInt(Windows.Forms.Cursor.Position.X.ToString)

    YCo = CInt(Windows.Forms.Cursor.Position.Y.ToString)

    MsgBox(XCo) 'erase

    MsgBox(YCo) 'erase

    ...

    End Sub


  • Tryst


    Dim zMousePointInScreenCoordinates As Point = System.Windows.Forms.Cursor.Position
    Dim zMousePointOnMyControl As Point = MyControl.PointToClient(zMousePointInScreenCoordinates)
    Dim Xco, Yco As Integer
    Xco = zMousePointOnMyControl.X
    Yco = zMousePointOnMyControl.Y

  • xavito

    Hi!! Im a begginer with programming, so forvige me is my question is so s****. Im trying to translate this code to visual basic 6.0, but Im having some problems with "IntPtr" (I believe that visual basic basic 6.0 does not recognize it as a type). What can I replace it with

    Thanks a lot!!!

    Thomas


  • Enkht

    Okay, now, is there any way to tell where the mouse is on the screen Not during my program, but if I want to figure out where, let's say, Internet Explorer is on the screen before I write the program, how do I do that Is there any program out there that can tell me the coordinates of the mouse (Not for my program, just to see where things are for when I write the program.)

  • Is there any way to autoclick with the mouse?