From 3291faad539a4744df25fa7751f80441d32302c8 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Wed, 17 Oct 2018 16:12:48 -0400 Subject: [PATCH 1/2] use sendInput not keybd_event [docs: Note This function has been superseded] --- key/keypress_c.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/key/keypress_c.h b/key/keypress_c.h index 0ff73b8..6440a5a 100644 --- a/key/keypress_c.h +++ b/key/keypress_c.h @@ -103,7 +103,17 @@ void win32KeyEvent(int key, MMKeyFlags flags){ // scan |= 0x80; // } - keybd_event(key, scan, flags, 0); + // keybd_event(key, scan, flags, 0); + + INPUT keyInput; + + keyInput.type = INPUT_KEYBOARD; + keyInput.ki.wVk = key; + keyInput.ki.wScan = scan; + keyInput.ki.dwFlags = flags; + keyInput.ki.time = 0; + keyInput.ki.dwExtraInfo = 0; + SendInput(1, &keyInput, sizeof(keyInput)); } #endif From 323eed683da69e53c23ab7cacc8c61eeeb231687 Mon Sep 17 00:00:00 2001 From: vcaesar Date: Wed, 17 Oct 2018 16:20:28 -0400 Subject: [PATCH 2/2] use sendInput not mouse_event and update code style --- mouse/mouse_c.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/mouse/mouse_c.h b/mouse/mouse_c.h index 5704d17..b9217ba 100644 --- a/mouse/mouse_c.h +++ b/mouse/mouse_c.h @@ -180,8 +180,8 @@ 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); #elif defined(USE_X11) @@ -189,7 +189,18 @@ void toggleMouse(bool down, MMMouseButton button){ XTestFakeButtonEvent(display, button, down ? True : False, CurrentTime); XSync(display, false); #elif defined(IS_WINDOWS) - mouse_event(MMMouseToMEventF(down, button), 0, 0, 0, 0); + // mouse_event(MMMouseToMEventF(down, button), 0, 0, 0, 0); + + INPUT mouseInput; + + mouseInput.type = INPUT_MOUSE; + mouseInput.mi.dx = 0; + mouseInput.mi.dy = 0; + mouseInput.mi.dwFlags = MMMouseToMEventF(down, button); + mouseInput.mi.time = 0; + mouseInput.mi.dwExtraInfo = 0; + mouseInput.mi.mouseData = 0; + SendInput(1, &mouseInput, sizeof(mouseInput)); #endif } @@ -261,7 +272,9 @@ void scrollMouse(int scrollMagnitude, MMMouseWheelDirection scrollDirection){ /* Make scroll magnitude negative if we're scrolling down. */ cleanScrollMagnitude = cleanScrollMagnitude * scrollDirection; - event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitLine, wheel, cleanScrollMagnitude, 0); + event = CGEventCreateScrollWheelEvent(NULL, + kCGScrollEventUnitLine, wheel, cleanScrollMagnitude, 0); + CGEventPost(kCGHIDEventTap, event); #elif defined(USE_X11)