Skip to content

Commit

Permalink
Update windows int type
Browse files Browse the repository at this point in the history
  • Loading branch information
vcaesar committed Jan 4, 2022
1 parent cf23717 commit 7685ce8
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions mouse/mouse_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,16 @@ void calculateDeltas(CGEventRef *event, MMPointInt32 point){
*/
void moveMouse(MMPointInt32 point){
#if defined(IS_MACOSX)
CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
CGPointFromMMPointInt32(point),
kCGMouseButtonLeft);
CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
CGPointFromMMPointInt32(point), kCGMouseButtonLeft);

calculateDeltas(&move, point);

CGEventPost(kCGSessionEventTap, move);
CFRelease(move);
#elif defined(USE_X11)
Display *display = XGetMainDisplay();
XWarpPointer(display, None, DefaultRootWindow(display),
0, 0, 0, 0, point.x, point.y);
XWarpPointer(display, None, DefaultRootWindow(display), 0, 0, 0, 0, point.x, point.y);

XSync(display, false);
#elif defined(IS_WINDOWS)
Expand All @@ -114,15 +112,16 @@ void moveMouse(MMPointInt32 point){
((65536 * coord) / width_or_height) + (coord < 0 ? -1 : 1))

MMRectInt32 rect = getScreenRect(-1);
size_t x = MOUSE_COORD_TO_ABS(point.x - rect.origin.x, rect.size.w);
size_t y = MOUSE_COORD_TO_ABS(point.y - rect.origin.y, rect.size.h);
int32_t x = MOUSE_COORD_TO_ABS(point.x - rect.origin.x, rect.size.w);
int32_t y = MOUSE_COORD_TO_ABS(point.y - rect.origin.y, rect.size.h);

INPUT mouseInput;
mouseInput.type = INPUT_MOUSE;
mouseInput.mi.dx = x;
mouseInput.mi.dy = y;
mouseInput.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE | MOUSEEVENTF_VIRTUALDESK;
mouseInput.mi.time = 0; // System will provide the timestamp

mouseInput.mi.dwExtraInfo = 0;
mouseInput.mi.mouseData = 0;
SendInput(1, &mouseInput, sizeof(mouseInput));
Expand All @@ -133,8 +132,8 @@ void moveMouse(MMPointInt32 point){
void dragMouse(MMPointInt32 point, const MMMouseButton button){
#if defined(IS_MACOSX)
const CGEventType dragType = MMMouseDragToCGEventType(button);
CGEventRef drag = CGEventCreateMouseEvent(NULL, dragType,
CGPointFromMMPoint(point), (CGMouseButton)button);
CGEventRef drag = CGEventCreateMouseEvent(NULL, dragType,
CGPointFromMMPoint(point), (CGMouseButton)button);

calculateDeltas(&drag, point);

Expand Down Expand Up @@ -181,7 +180,7 @@ void toggleMouse(bool down, MMMouseButton button){
const CGPoint currentPos = CGPointFromMMPoint(getMousePos());
const CGEventType mouseType = MMMouseToCGEventType(down, button);
CGEventRef event = CGEventCreateMouseEvent(NULL,
mouseType, currentPos, (CGMouseButton)button);
mouseType, currentPos, (CGMouseButton)button);

CGEventPost(kCGSessionEventTap, event);
CFRelease(event);
Expand All @@ -191,7 +190,6 @@ void toggleMouse(bool down, MMMouseButton button){
XSync(display, false);
#elif defined(IS_WINDOWS)
// mouse_event(MMMouseToMEventF(down, button), 0, 0, 0, 0);

INPUT mouseInput;

mouseInput.type = INPUT_MOUSE;
Expand Down Expand Up @@ -224,7 +222,7 @@ void doubleClick(MMMouseButton button){
const CGEventType mouseTypeUP = MMMouseToCGEventType(false, button);

CGEventRef event = CGEventCreateMouseEvent(
NULL, mouseTypeDown, currentPos, kCGMouseButtonLeft);
NULL, mouseTypeDown, currentPos, kCGMouseButtonLeft);

/* Set event to double click. */
CGEventSetIntegerValueField(event, kCGMouseEventClickState, 2);
Expand Down Expand Up @@ -275,7 +273,7 @@ void scrollMouse(int scrollMagnitude, MMMouseWheelDirection scrollDirection){
cleanScrollMagnitude = cleanScrollMagnitude * scrollDirection;

event = CGEventCreateScrollWheelEvent(NULL,
kCGScrollEventUnitLine, wheel, cleanScrollMagnitude, 0);
kCGScrollEventUnitLine, wheel, cleanScrollMagnitude, 0);

CGEventPost(kCGHIDEventTap, event);

Expand Down

0 comments on commit 7685ce8

Please sign in to comment.