Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MOUSEEVENTF_ABSOLUTE doesn't work

Tags:

winapi

I want to make my program click specific mouse coordinates, so I am using

mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN, point.x, point.y, 0, 0);

where point.x and point.y are normalized between 0 and 65535. However, it always clicks where the cursor is instead of the coordinates that I pass. Why is that happening?

like image 359
xytor Avatar asked Sep 19 '25 13:09

xytor


2 Answers

You might be missing MOUSEEVENTF_MOVE flag.

If that doesn't work - I suggest you just use SetCursorPos() to set the location. Then your mouse_move event should work just fine.

like image 93
Mike Weir Avatar answered Sep 21 '25 10:09

Mike Weir


simulate all the mouse events

mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, point.x, point.y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
like image 22
gordy Avatar answered Sep 21 '25 08:09

gordy