83
83
/* Move the mouse to a specific point. */
84
84
void moveMouse (MMPointInt32 point ){
85
85
#if defined(IS_MACOSX )
86
- CGEventRef move = CGEventCreateMouseEvent (NULL , kCGEventMouseMoved ,
86
+ CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateHIDSystemState );
87
+ CGEventRef move = CGEventCreateMouseEvent (source , kCGEventMouseMoved ,
87
88
CGPointFromMMPointInt32 (point ), kCGMouseButtonLeft );
88
89
89
90
calculateDeltas (& move , point );
90
91
91
- CGEventPost (kCGSessionEventTap , move );
92
+ CGEventPost (kCGHIDEventTap , move );
92
93
CFRelease (move );
94
+ CFRelease (source );
93
95
#elif defined(USE_X11 )
94
96
Display * display = XGetMainDisplay ();
95
97
XWarpPointer (display , None , DefaultRootWindow (display ), 0 , 0 , 0 , 0 , point .x , point .y );
@@ -103,13 +105,15 @@ void moveMouse(MMPointInt32 point){
103
105
void dragMouse (MMPointInt32 point , const MMMouseButton button ){
104
106
#if defined(IS_MACOSX )
105
107
const CGEventType dragType = MMMouseDragToCGEventType (button );
106
- CGEventRef drag = CGEventCreateMouseEvent (NULL , dragType ,
108
+ CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateHIDSystemState );
109
+ CGEventRef drag = CGEventCreateMouseEvent (source , dragType ,
107
110
CGPointFromMMPointInt32 (point ), (CGMouseButton )button );
108
111
109
112
calculateDeltas (& drag , point );
110
113
111
- CGEventPost (kCGSessionEventTap , drag );
114
+ CGEventPost (kCGHIDEventTap , drag );
112
115
CFRelease (drag );
116
+ CFRelease (source );
113
117
#else
114
118
moveMouse (point );
115
119
#endif
@@ -145,10 +149,12 @@ void toggleMouse(bool down, MMMouseButton button) {
145
149
#if defined(IS_MACOSX )
146
150
const CGPoint currentPos = CGPointFromMMPointInt32 (location ());
147
151
const CGEventType mouseType = MMMouseToCGEventType (down , button );
148
- CGEventRef event = CGEventCreateMouseEvent (NULL , mouseType , currentPos , (CGMouseButton )button );
152
+ CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateHIDSystemState );
153
+ CGEventRef event = CGEventCreateMouseEvent (source , mouseType , currentPos , (CGMouseButton )button );
149
154
150
- CGEventPost (kCGSessionEventTap , event );
155
+ CGEventPost (kCGHIDEventTap , event );
151
156
CFRelease (event );
157
+ CFRelease (source );
152
158
#elif defined(USE_X11 )
153
159
Display * display = XGetMainDisplay ();
154
160
XTestFakeButtonEvent (display , button , down ? True : False , CurrentTime );
@@ -182,7 +188,8 @@ void doubleClick(MMMouseButton button){
182
188
const CGEventType mouseTypeDown = MMMouseToCGEventType (true, button );
183
189
const CGEventType mouseTypeUP = MMMouseToCGEventType (false, button );
184
190
185
- CGEventRef event = CGEventCreateMouseEvent (NULL , mouseTypeDown , currentPos , kCGMouseButtonLeft );
191
+ CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateHIDSystemState );
192
+ CGEventRef event = CGEventCreateMouseEvent (source , mouseTypeDown , currentPos , kCGMouseButtonLeft );
186
193
187
194
/* Set event to double click. */
188
195
CGEventSetIntegerValueField (event , kCGMouseEventClickState , 2 );
@@ -192,6 +199,7 @@ void doubleClick(MMMouseButton button){
192
199
CGEventPost (kCGHIDEventTap , event );
193
200
194
201
CFRelease (event );
202
+ CFRelease (source );
195
203
#else
196
204
/* Double click for everything else. */
197
205
clickMouse (button );
@@ -208,14 +216,13 @@ void scrollMouseXY(int x, int y) {
208
216
INPUT mouseScrollInputV ;
209
217
#endif
210
218
211
- /* Direction should only be considered based on the scrollDirection. This Should not interfere. */
212
- /* Set up the OS specific solution */
213
- #if defined(__APPLE__ )
214
- CGEventRef event ;
215
- event = CGEventCreateScrollWheelEvent (NULL , kCGScrollEventUnitPixel , 2 , y , x );
219
+ #if defined(IS_MACOSX )
220
+ CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateHIDSystemState );
221
+ CGEventRef event = CGEventCreateScrollWheelEvent (source , kCGScrollEventUnitPixel , 2 , y , x );
216
222
CGEventPost (kCGHIDEventTap , event );
217
223
218
224
CFRelease (event );
225
+ CFRelease (source );
219
226
#elif defined(USE_X11 )
220
227
int ydir = 4 ; /* Button 4 is up, 5 is down. */
221
228
int xdir = 6 ;
0 commit comments