mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-05-29 21:43:55 +00:00
Merge pull request #725 from go-vgo/bitmap-pr
Update: use hid event in macos
This commit is contained in:
commit
a8c387a070
@ -90,7 +90,8 @@ MMKeyCode keyCodeForChar(const char c) {
|
|||||||
|
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
CFStringRef createStringForKey(CGKeyCode keyCode){
|
CFStringRef createStringForKey(CGKeyCode keyCode){
|
||||||
TISInputSourceRef currentKeyboard = TISCopyCurrentASCIICapableKeyboardInputSource();
|
// TISInputSourceRef currentKeyboard = TISCopyCurrentASCIICapableKeyboardInputSource();
|
||||||
|
TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardLayoutInputSource();
|
||||||
CFDataRef layoutData = (CFDataRef) TISGetInputSourceProperty(
|
CFDataRef layoutData = (CFDataRef) TISGetInputSourceProperty(
|
||||||
currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
|
currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@
|
|||||||
if (pid != 0) {
|
if (pid != 0) {
|
||||||
CGEventPostToPid(pid, event);
|
CGEventPostToPid(pid, event);
|
||||||
} else {
|
} else {
|
||||||
CGEventPost(kCGSessionEventTap, event);
|
CGEventPost(kCGHIDEventTap, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
CFRelease(event);
|
CFRelease(event);
|
||||||
@ -179,7 +179,8 @@ void toggleKeyCode(MMKeyCode code, const bool down, MMKeyFlags flags, uintptr pi
|
|||||||
NX_SYSDEFINED, loc, &event, kNXEventDataVersion, 0, FALSE);
|
NX_SYSDEFINED, loc, &event, kNXEventDataVersion, 0, FALSE);
|
||||||
assert(KERN_SUCCESS == kr);
|
assert(KERN_SUCCESS == kr);
|
||||||
} else {
|
} else {
|
||||||
CGEventRef keyEvent = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)code, down);
|
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||||
|
CGEventRef keyEvent = CGEventCreateKeyboardEvent(source, (CGKeyCode)code, down);
|
||||||
assert(keyEvent != NULL);
|
assert(keyEvent != NULL);
|
||||||
|
|
||||||
CGEventSetType(keyEvent, down ? kCGEventKeyDown : kCGEventKeyUp);
|
CGEventSetType(keyEvent, down ? kCGEventKeyDown : kCGEventKeyUp);
|
||||||
@ -188,6 +189,7 @@ void toggleKeyCode(MMKeyCode code, const bool down, MMKeyFlags flags, uintptr pi
|
|||||||
}
|
}
|
||||||
|
|
||||||
SendTo(pid, keyEvent);
|
SendTo(pid, keyEvent);
|
||||||
|
CFRelease(source);
|
||||||
}
|
}
|
||||||
#elif defined(IS_WINDOWS)
|
#elif defined(IS_WINDOWS)
|
||||||
const DWORD dwFlags = down ? 0 : KEYEVENTF_KEYUP;
|
const DWORD dwFlags = down ? 0 : KEYEVENTF_KEYUP;
|
||||||
@ -273,7 +275,8 @@ void toggleKey(char c, const bool down, MMKeyFlags flags, uintptr pid) {
|
|||||||
convert characters to a keycode, but does not support adding modifier flags.
|
convert characters to a keycode, but does not support adding modifier flags.
|
||||||
It is only used in typeString().
|
It is only used in typeString().
|
||||||
-- if you need modifier keys, use the above functions instead. */
|
-- if you need modifier keys, use the above functions instead. */
|
||||||
CGEventRef keyEvent = CGEventCreateKeyboardEvent(NULL, 0, down);
|
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||||
|
CGEventRef keyEvent = CGEventCreateKeyboardEvent(source, 0, down);
|
||||||
if (keyEvent == NULL) {
|
if (keyEvent == NULL) {
|
||||||
fputs("Could not create keyboard event.\n", stderr);
|
fputs("Could not create keyboard event.\n", stderr);
|
||||||
return;
|
return;
|
||||||
@ -282,6 +285,7 @@ void toggleKey(char c, const bool down, MMKeyFlags flags, uintptr pid) {
|
|||||||
CGEventKeyboardSetUnicodeString(keyEvent, 1, &ch);
|
CGEventKeyboardSetUnicodeString(keyEvent, 1, &ch);
|
||||||
|
|
||||||
SendTo(pid, keyEvent);
|
SendTo(pid, keyEvent);
|
||||||
|
CFRelease(source);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define toggleUniKey(c, down) toggleKey(c, down, MOD_NONE, 0)
|
#define toggleUniKey(c, down) toggleKey(c, down, MOD_NONE, 0)
|
||||||
|
@ -83,13 +83,15 @@
|
|||||||
/* Move the mouse to a specific point. */
|
/* Move the mouse to a specific point. */
|
||||||
void moveMouse(MMPointInt32 point){
|
void moveMouse(MMPointInt32 point){
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
|
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||||
|
CGEventRef move = CGEventCreateMouseEvent(source, kCGEventMouseMoved,
|
||||||
CGPointFromMMPointInt32(point), kCGMouseButtonLeft);
|
CGPointFromMMPointInt32(point), kCGMouseButtonLeft);
|
||||||
|
|
||||||
calculateDeltas(&move, point);
|
calculateDeltas(&move, point);
|
||||||
|
|
||||||
CGEventPost(kCGSessionEventTap, move);
|
CGEventPost(kCGHIDEventTap, move);
|
||||||
CFRelease(move);
|
CFRelease(move);
|
||||||
|
CFRelease(source);
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
Display *display = XGetMainDisplay();
|
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);
|
||||||
@ -103,13 +105,15 @@ void moveMouse(MMPointInt32 point){
|
|||||||
void dragMouse(MMPointInt32 point, const MMMouseButton button){
|
void dragMouse(MMPointInt32 point, const MMMouseButton button){
|
||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
const CGEventType dragType = MMMouseDragToCGEventType(button);
|
const CGEventType dragType = MMMouseDragToCGEventType(button);
|
||||||
CGEventRef drag = CGEventCreateMouseEvent(NULL, dragType,
|
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||||
|
CGEventRef drag = CGEventCreateMouseEvent(source, dragType,
|
||||||
CGPointFromMMPointInt32(point), (CGMouseButton)button);
|
CGPointFromMMPointInt32(point), (CGMouseButton)button);
|
||||||
|
|
||||||
calculateDeltas(&drag, point);
|
calculateDeltas(&drag, point);
|
||||||
|
|
||||||
CGEventPost(kCGSessionEventTap, drag);
|
CGEventPost(kCGHIDEventTap, drag);
|
||||||
CFRelease(drag);
|
CFRelease(drag);
|
||||||
|
CFRelease(source);
|
||||||
#else
|
#else
|
||||||
moveMouse(point);
|
moveMouse(point);
|
||||||
#endif
|
#endif
|
||||||
@ -145,10 +149,12 @@ void toggleMouse(bool down, MMMouseButton button) {
|
|||||||
#if defined(IS_MACOSX)
|
#if defined(IS_MACOSX)
|
||||||
const CGPoint currentPos = CGPointFromMMPointInt32(location());
|
const CGPoint currentPos = CGPointFromMMPointInt32(location());
|
||||||
const CGEventType mouseType = MMMouseToCGEventType(down, button);
|
const CGEventType mouseType = MMMouseToCGEventType(down, button);
|
||||||
CGEventRef event = CGEventCreateMouseEvent(NULL, mouseType, currentPos, (CGMouseButton)button);
|
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||||
|
CGEventRef event = CGEventCreateMouseEvent(source, mouseType, currentPos, (CGMouseButton)button);
|
||||||
|
|
||||||
CGEventPost(kCGSessionEventTap, event);
|
CGEventPost(kCGHIDEventTap, event);
|
||||||
CFRelease(event);
|
CFRelease(event);
|
||||||
|
CFRelease(source);
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
Display *display = XGetMainDisplay();
|
Display *display = XGetMainDisplay();
|
||||||
XTestFakeButtonEvent(display, button, down ? True : False, CurrentTime);
|
XTestFakeButtonEvent(display, button, down ? True : False, CurrentTime);
|
||||||
@ -182,7 +188,8 @@ void doubleClick(MMMouseButton button){
|
|||||||
const CGEventType mouseTypeDown = MMMouseToCGEventType(true, button);
|
const CGEventType mouseTypeDown = MMMouseToCGEventType(true, button);
|
||||||
const CGEventType mouseTypeUP = MMMouseToCGEventType(false, button);
|
const CGEventType mouseTypeUP = MMMouseToCGEventType(false, button);
|
||||||
|
|
||||||
CGEventRef event = CGEventCreateMouseEvent(NULL, mouseTypeDown, currentPos, kCGMouseButtonLeft);
|
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||||
|
CGEventRef event = CGEventCreateMouseEvent(source, mouseTypeDown, currentPos, kCGMouseButtonLeft);
|
||||||
|
|
||||||
/* Set event to double click. */
|
/* Set event to double click. */
|
||||||
CGEventSetIntegerValueField(event, kCGMouseEventClickState, 2);
|
CGEventSetIntegerValueField(event, kCGMouseEventClickState, 2);
|
||||||
@ -192,6 +199,7 @@ void doubleClick(MMMouseButton button){
|
|||||||
CGEventPost(kCGHIDEventTap, event);
|
CGEventPost(kCGHIDEventTap, event);
|
||||||
|
|
||||||
CFRelease(event);
|
CFRelease(event);
|
||||||
|
CFRelease(source);
|
||||||
#else
|
#else
|
||||||
/* Double click for everything else. */
|
/* Double click for everything else. */
|
||||||
clickMouse(button);
|
clickMouse(button);
|
||||||
@ -208,14 +216,13 @@ void scrollMouseXY(int x, int y) {
|
|||||||
INPUT mouseScrollInputV;
|
INPUT mouseScrollInputV;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Direction should only be considered based on the scrollDirection. This Should not interfere. */
|
#if defined(IS_MACOSX)
|
||||||
/* Set up the OS specific solution */
|
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||||
#if defined(__APPLE__)
|
CGEventRef event = CGEventCreateScrollWheelEvent(source, kCGScrollEventUnitPixel, 2, y, x);
|
||||||
CGEventRef event;
|
|
||||||
event = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 2, y, x);
|
|
||||||
CGEventPost(kCGHIDEventTap, event);
|
CGEventPost(kCGHIDEventTap, event);
|
||||||
|
|
||||||
CFRelease(event);
|
CFRelease(event);
|
||||||
|
CFRelease(source);
|
||||||
#elif defined(USE_X11)
|
#elif defined(USE_X11)
|
||||||
int ydir = 4; /* Button 4 is up, 5 is down. */
|
int ydir = 4; /* Button 4 is up, 5 is down. */
|
||||||
int xdir = 6;
|
int xdir = 6;
|
||||||
|
Loading…
Reference in New Issue
Block a user