|
1 | 1 | #include "../mouse.h"
|
| 2 | +#include "../screen.h" |
2 | 3 | #include "../microsleep.h"
|
3 | 4 |
|
4 | 5 | #include <math.h> /* For floor() */
|
|
7 | 8 | #define M_SQRT2 1.4142135623730950488016887 /* Fix for MSVC. */
|
8 | 9 | #endif
|
9 | 10 |
|
| 11 | +/** |
| 12 | + * This constant is required as Windows divides the entire |
| 13 | + * screen space into 65536 segments in both X and Y axes |
| 14 | + * irrespective of resolution |
| 15 | + * https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-mouseinput#remarks |
| 16 | + */ |
| 17 | + #define ABSOLUTE_COORD_CONST 65536 |
| 18 | + |
| 19 | + |
10 | 20 | #define MMMouseToMEventF(down, button) \
|
11 | 21 | (down ? MMMouseDownToMEventF(button) : MMMouseUpToMEventF(button))
|
12 | 22 |
|
|
20 | 30 | : ((button) == RIGHT_BUTTON ? MOUSEEVENTF_RIGHTDOWN \
|
21 | 31 | : MOUSEEVENTF_MIDDLEDOWN))
|
22 | 32 |
|
| 33 | +MMPoint CalculateAbsoluteCoordinates(MMPoint point) { |
| 34 | + MMSize displaySize = getMainDisplaySize(); |
| 35 | + return MMPointMake((point.x / displaySize.width) * ABSOLUTE_COORD_CONST, (point.y / displaySize.height) * ABSOLUTE_COORD_CONST); |
| 36 | +} |
| 37 | + |
23 | 38 | /**
|
24 | 39 | * Move the mouse to a specific point.
|
25 | 40 | * @param point The coordinates to move the mouse to (x, y).
|
26 | 41 | */
|
27 |
| -void moveMouse(MMPoint point) |
28 |
| -{ |
29 |
| - SetCursorPos ((int)point.x, (int)point.y); |
| 42 | +void moveMouse(MMPoint point) { |
| 43 | + INPUT mouseInput; |
| 44 | + MMPoint pointAbsolute = CalculateAbsoluteCoordinates(point); |
| 45 | + mouseInput.type = INPUT_MOUSE; |
| 46 | + mouseInput.mi.dx = pointAbsolute.x; |
| 47 | + mouseInput.mi.dy = pointAbsolute.y; |
| 48 | + mouseInput.mi.mouseData = 0; |
| 49 | + mouseInput.mi.time = 0; |
| 50 | + mouseInput.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE; |
| 51 | + mouseInput.mi.dwExtraInfo = 0; |
| 52 | + SendInput(1, & mouseInput, sizeof(mouseInput)); |
30 | 53 | }
|
31 | 54 |
|
32 | 55 | void dragMouse(MMPoint point, const MMMouseButton button)
|
|
0 commit comments