57
57
#endif
58
58
59
59
/**
60
- * Move the mouse to a specific point.
61
- * @param point The coordinates to move the mouse to (x, y).
60
+ * Calculate the delta for a mouse move and add them to the event.
61
+ * @param event The mouse move event (by ref).
62
+ * @param point The new mouse x and y.
62
63
*/
63
- void moveMouse ( MMPoint point )
64
+ void calculateDeltas ( CGEventRef * event , MMPoint point )
64
65
{
65
- #if defined(IS_MACOSX )
66
- CGEventRef move = CGEventCreateMouseEvent (NULL , kCGEventMouseMoved ,
67
- CGPointFromMMPoint (point ),
68
- kCGMouseButtonLeft );
69
-
70
-
71
66
/**
72
67
* The next few lines are a workaround for games not detecting mouse moves.
73
68
* See this issue for more information:
@@ -80,11 +75,27 @@ void moveMouse(MMPoint point)
80
75
int64_t deltaX = point .x - mouse .x ;
81
76
int64_t deltaY = point .y - mouse .y ;
82
77
83
- CGEventSetIntegerValueField (move , kCGMouseEventDeltaX , deltaX );
84
- CGEventSetIntegerValueField (move , kCGMouseEventDeltaY , deltaY );
78
+ CGEventSetIntegerValueField (* event , kCGMouseEventDeltaX , deltaX );
79
+ CGEventSetIntegerValueField (* event , kCGMouseEventDeltaY , deltaY );
85
80
86
- CGEventPost (kCGSessionEventTap , move );
87
81
CFRelease (get );
82
+ }
83
+
84
+
85
+ /**
86
+ * Move the mouse to a specific point.
87
+ * @param point The coordinates to move the mouse to (x, y).
88
+ */
89
+ void moveMouse (MMPoint point )
90
+ {
91
+ #if defined(IS_MACOSX )
92
+ CGEventRef move = CGEventCreateMouseEvent (NULL , kCGEventMouseMoved ,
93
+ CGPointFromMMPoint (point ),
94
+ kCGMouseButtonLeft );
95
+
96
+ calculateDeltas (& move , point );
97
+
98
+ CGEventPost (kCGSessionEventTap , move );
88
99
CFRelease (move );
89
100
#elif defined(USE_X11 )
90
101
Display * display = XGetMainDisplay ();
@@ -104,9 +115,11 @@ void dragMouse(MMPoint point, const MMMouseButton button)
104
115
{
105
116
#if defined(IS_MACOSX )
106
117
const CGEventType dragType = MMMouseDragToCGEventType (button );
107
- const CGEventRef drag = CGEventCreateMouseEvent (NULL , dragType ,
118
+ CGEventRef drag = CGEventCreateMouseEvent (NULL , dragType ,
108
119
CGPointFromMMPoint (point ),
109
120
(CGMouseButton )button );
121
+ calculateDeltas (& drag , point );
122
+
110
123
CGEventPost (kCGSessionEventTap , drag );
111
124
CFRelease (drag );
112
125
#else
0 commit comments