@@ -90,35 +90,45 @@ void calculateDeltas(CGEventRef *event, MMPoint point)
90
90
*/
91
91
void moveMouse (MMPoint point )
92
92
{
93
- #if defined(IS_MACOSX )
94
- CGEventRef move = CGEventCreateMouseEvent (NULL , kCGEventMouseMoved ,
95
- CGPointFromMMPoint (point ),
96
- kCGMouseButtonLeft );
97
-
98
- calculateDeltas (& move , point );
99
-
100
- CGEventPost (kCGSessionEventTap , move );
101
- CFRelease (move );
102
- #elif defined(USE_X11 )
93
+ #ifdef USE_X11
103
94
Display * display = XGetMainDisplay ();
104
95
XWarpPointer (display , None , DefaultRootWindow (display ),
105
96
0 , 0 , 0 , 0 , point .x , point .y );
106
97
XSync (display , false);
107
- #elif defined(IS_WINDOWS )
108
- //Mouse motion is now done using SendInput with MOUSEINPUT. We use Absolute mouse positioning
109
- #define MOUSE_COORD_TO_ABS (coord , width_or_height ) (((65536 * coord) / width_or_height) + (coord < 0 ? -1 : 1))
110
- point .x = MOUSE_COORD_TO_ABS (point .x , GetSystemMetrics (SM_CXSCREEN ));
111
- point .y = MOUSE_COORD_TO_ABS (point .y , GetSystemMetrics (SM_CYSCREEN ));
112
- INPUT mouseInput ;
113
- mouseInput .type = INPUT_MOUSE ;
114
- mouseInput .mi .dx = point .x ;
115
- mouseInput .mi .dy = point .y ;
116
- mouseInput .mi .dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE ;
117
- mouseInput .mi .time = 0 ; //System will provide the timestamp
118
- mouseInput .mi .dwExtraInfo = 0 ;
119
- mouseInput .mi .mouseData = 0 ;
120
- SendInput (1 , & mouseInput , sizeof (mouseInput ));
98
+ #endif
99
+ #ifdef IS_MACOSX
100
+ CGPoint position = CGPointMake (point .x , point .y );
101
+ // Create an HID hardware event source
102
+ CGEventSourceRef src = CGEventSourceCreate
103
+ (kCGEventSourceStateHIDSystemState );
104
+
105
+ CGEventRef evt = nullptr ;
106
+ if (CGEventSourceButtonState (kCGEventSourceStateHIDSystemState , kCGMouseButtonLeft )) {
107
+ // Create a left button drag
108
+ evt = CGEventCreateMouseEvent
109
+ (src , kCGEventLeftMouseDragged ,
110
+ position , kCGMouseButtonLeft );
111
+ } else {
112
+ if (CGEventSourceButtonState (kCGEventSourceStateHIDSystemState , kCGMouseButtonRight )) {
113
+ // Create a right button drag
114
+ evt = CGEventCreateMouseEvent
115
+ (src , kCGEventRightMouseDragged ,
116
+ position , kCGMouseButtonLeft );
117
+ } else {
118
+ // Create a mouse move event
119
+ evt = CGEventCreateMouseEvent
120
+ (src , kCGEventMouseMoved ,
121
+ position , kCGMouseButtonLeft );
122
+ }
123
+ }
121
124
125
+ // Post mouse event and release
126
+ CGEventPost (kCGHIDEventTap , evt );
127
+ CFRelease (evt );
128
+ CFRelease (src );
129
+ #endif
130
+ #ifdef IS_WINDOWS
131
+ SetCursorPos (point .x , point .y );
122
132
#endif
123
133
}
124
134
0 commit comments