8383/* Move the mouse to a specific point. */
8484void moveMouse (MMPointInt32 point ){
8585 #if defined(IS_MACOSX )
86- CGEventRef move = CGEventCreateMouseEvent (NULL , kCGEventMouseMoved ,
86+ CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateHIDSystemState );
87+ CGEventRef move = CGEventCreateMouseEvent (source , kCGEventMouseMoved ,
8788 CGPointFromMMPointInt32 (point ), kCGMouseButtonLeft );
8889
8990 calculateDeltas (& move , point );
9091
91- CGEventPost (kCGSessionEventTap , move );
92+ CGEventPost (kCGHIDEventTap , move );
9293 CFRelease (move );
94+ CFRelease (source );
9395 #elif defined(USE_X11 )
9496 Display * display = XGetMainDisplay ();
9597 XWarpPointer (display , None , DefaultRootWindow (display ), 0 , 0 , 0 , 0 , point .x , point .y );
@@ -103,13 +105,15 @@ void moveMouse(MMPointInt32 point){
103105void dragMouse (MMPointInt32 point , const MMMouseButton button ){
104106 #if defined(IS_MACOSX )
105107 const CGEventType dragType = MMMouseDragToCGEventType (button );
106- CGEventRef drag = CGEventCreateMouseEvent (NULL , dragType ,
108+ CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateHIDSystemState );
109+ CGEventRef drag = CGEventCreateMouseEvent (source , dragType ,
107110 CGPointFromMMPointInt32 (point ), (CGMouseButton )button );
108111
109112 calculateDeltas (& drag , point );
110113
111- CGEventPost (kCGSessionEventTap , drag );
114+ CGEventPost (kCGHIDEventTap , drag );
112115 CFRelease (drag );
116+ CFRelease (source );
113117 #else
114118 moveMouse (point );
115119 #endif
@@ -145,10 +149,12 @@ void toggleMouse(bool down, MMMouseButton button) {
145149 #if defined(IS_MACOSX )
146150 const CGPoint currentPos = CGPointFromMMPointInt32 (location ());
147151 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 );
149154
150- CGEventPost (kCGSessionEventTap , event );
155+ CGEventPost (kCGHIDEventTap , event );
151156 CFRelease (event );
157+ CFRelease (source );
152158 #elif defined(USE_X11 )
153159 Display * display = XGetMainDisplay ();
154160 XTestFakeButtonEvent (display , button , down ? True : False , CurrentTime );
@@ -182,7 +188,8 @@ void doubleClick(MMMouseButton button){
182188 const CGEventType mouseTypeDown = MMMouseToCGEventType (true, button );
183189 const CGEventType mouseTypeUP = MMMouseToCGEventType (false, button );
184190
185- CGEventRef event = CGEventCreateMouseEvent (NULL , mouseTypeDown , currentPos , kCGMouseButtonLeft );
191+ CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateHIDSystemState );
192+ CGEventRef event = CGEventCreateMouseEvent (source , mouseTypeDown , currentPos , kCGMouseButtonLeft );
186193
187194 /* Set event to double click. */
188195 CGEventSetIntegerValueField (event , kCGMouseEventClickState , 2 );
@@ -192,6 +199,7 @@ void doubleClick(MMMouseButton button){
192199 CGEventPost (kCGHIDEventTap , event );
193200
194201 CFRelease (event );
202+ CFRelease (source );
195203 #else
196204 /* Double click for everything else. */
197205 clickMouse (button );
@@ -208,14 +216,13 @@ void scrollMouseXY(int x, int y) {
208216 INPUT mouseScrollInputV ;
209217 #endif
210218
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 );
216222 CGEventPost (kCGHIDEventTap , event );
217223
218224 CFRelease (event );
225+ CFRelease (source );
219226 #elif defined(USE_X11 )
220227 int ydir = 4 ; /* Button 4 is up, 5 is down. */
221228 int xdir = 6 ;
0 commit comments