Skip to content

Commit 9e3a067

Browse files
committed
Workaround for games not detecting mouse moves.
1 parent d2d859a commit 9e3a067

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/mouse.c

+18
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,25 @@ void moveMouse(MMPoint point)
6666
CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
6767
CGPointFromMMPoint(point),
6868
kCGMouseButtonLeft);
69+
70+
71+
/**
72+
* The next few lines are a workaround for games not detecting mouse moves.
73+
* See this issue for more information:
74+
* https://github.com/octalmage/robotjs/issues/159
75+
*/
76+
CGEventRef get = CGEventCreate(NULL);
77+
CGPoint mouse = CGEventGetLocation(get);
78+
79+
// Calculate the deltas.
80+
int64_t deltaX = point.x - mouse.x;
81+
int64_t deltaY = point.y -mouse.y;
82+
83+
CGEventSetIntegerValueField(move, kCGMouseEventDeltaY, deltaX);
84+
CGEventSetIntegerValueField(move, kCGMouseEventDeltaX, deltaY);
85+
6986
CGEventPost(kCGSessionEventTap, move);
87+
CFRelease(get);
7088
CFRelease(move);
7189
#elif defined(USE_X11)
7290
Display *display = XGetMainDisplay();

0 commit comments

Comments
 (0)