Skip to content

Commit

Permalink
Workaround for games not detecting mouse moves.
Browse files Browse the repository at this point in the history
  • Loading branch information
octalmage committed Apr 10, 2016
1 parent d2d859a commit 9e3a067
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,25 @@ void moveMouse(MMPoint point)
CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
CGPointFromMMPoint(point),
kCGMouseButtonLeft);


/**
* The next few lines are a workaround for games not detecting mouse moves.
* See this issue for more information:
* https://github.com/octalmage/robotjs/issues/159
*/
CGEventRef get = CGEventCreate(NULL);
CGPoint mouse = CGEventGetLocation(get);

// Calculate the deltas.
int64_t deltaX = point.x - mouse.x;
int64_t deltaY = point.y -mouse.y;

CGEventSetIntegerValueField(move, kCGMouseEventDeltaY, deltaX);
CGEventSetIntegerValueField(move, kCGMouseEventDeltaX, deltaY);

CGEventPost(kCGSessionEventTap, move);
CFRelease(get);
CFRelease(move);
#elif defined(USE_X11)
Display *display = XGetMainDisplay();
Expand Down

0 comments on commit 9e3a067

Please sign in to comment.