Mouse Send Click on a specific position without moving the mouse

I want to send a mouse click to a specific position on the screen without affecting the location of the mouse cursor.

I read and tried everything under the sun with mouse_event (which should do this)

mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0); 

However, this ends up just sending the mouse click to where the mouse pointer is. So I have to move the mouse to make it work.

 Cursor.Position = new Point(X, Y); 

Does anyone know how I can do this WITHOUT having to move the mouse? I also tried the following block of code without success, as it still only clicked where the mouse cursor position was indicated, which really threw me into the loop, as I figured it would work ...

  Cursor.Position = new Point(X, Y); mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0); Cursor.Position = new Point(oldX, oldY); 

Thanks in advance for your help!

+4
source share
4 answers

You did not specify the MOUSEEVENTF_MOVE flag, so the cursor will not move.

I would recommend making 3 different calls (moving, lowering, up), doing everything at the same time iffy. But it may work, experiment if you really want to cut it. Btw, SendInput is what recommends using the SDK.

+1
source

You probably place the mouse click in the wrong place. mouse_event takes X and Y values ​​in mickeys, as described in the documentation here .

Try converting your location with something like this:

 private static Point ScreenLocationToMickeyLocation( Point mouseLocation ) { Rectangle virtualScreen = SystemInformation.VirtualScreen; return new Point( ( ( mouseLocation.X - virtualScreen.X ) * 65535 ) / virtualScreen.Width, ( ( mouseLocation.Y - virtualScreen.Y ) * 65535 ) / virtualScreen.Height ); } 
0
source

You might want to try to capture the current location of the mouse, move the mouse to where you want to click it, click on the location, and then move the mouse back. If this is done fast enough, it looks like the mouse did not move.

0
source

2015 Community Visual Basic Declaration

Imports System.Runtime.InteropServices

 <Flags()> Public Enum MouseEventFlags As UInteger MOUSEEVENTF_ABSOLUTE = &H8000 MOUSEEVENTF_LEFTDOWN = &H2 MOUSEEVENTF_LEFTUP = &H4 MOUSEEVENTF_MIDDLEDOWN = &H20 MOUSEEVENTF_MIDDLEUP = &H40 MOUSEEVENTF_MOVE = &H1 MOUSEEVENTF_RIGHTDOWN = &H8 MOUSEEVENTF_RIGHTUP = &H10 MOUSEEVENTF_XDOWN = &H80 MOUSEEVENTF_XUP = &H100 MOUSEEVENTF_WHEEL = &H800 MOUSEEVENTF_HWHEEL = &H1000 End Enum Dim pntapi As POINTAPI Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (ByRef lpPoint As POINTAPI) As Integer Declare Function SetCursorPos Lib "user32" Alias "SetCursorPos" (ByVal X As Integer, ByVal Y As Integer) As Integer Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal dwData As Integer, ByVal dwExtraInfo As Integer) 
0
source

All Articles