mirror of
https://github.com/go-vgo/robotgo.git
synced 2025-05-29 21:43:55 +00:00
Update: use hid event in macos
This commit is contained in:
parent
73c07dc991
commit
5c2864485d
@ -90,7 +90,8 @@ MMKeyCode keyCodeForChar(const char c) {
|
||||
|
||||
#if defined(IS_MACOSX)
|
||||
CFStringRef createStringForKey(CGKeyCode keyCode){
|
||||
TISInputSourceRef currentKeyboard = TISCopyCurrentASCIICapableKeyboardInputSource();
|
||||
// TISInputSourceRef currentKeyboard = TISCopyCurrentASCIICapableKeyboardInputSource();
|
||||
TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardLayoutInputSource();
|
||||
CFDataRef layoutData = (CFDataRef) TISGetInputSourceProperty(
|
||||
currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
|
||||
|
||||
|
@ -58,7 +58,7 @@
|
||||
if (pid != 0) {
|
||||
CGEventPostToPid(pid, event);
|
||||
} else {
|
||||
CGEventPost(kCGSessionEventTap, event);
|
||||
CGEventPost(kCGHIDEventTap, 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);
|
||||
assert(KERN_SUCCESS == kr);
|
||||
} else {
|
||||
CGEventRef keyEvent = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)code, down);
|
||||
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||
CGEventRef keyEvent = CGEventCreateKeyboardEvent(source, (CGKeyCode)code, down);
|
||||
assert(keyEvent != NULL);
|
||||
|
||||
CGEventSetType(keyEvent, down ? kCGEventKeyDown : kCGEventKeyUp);
|
||||
@ -273,7 +274,8 @@ void toggleKey(char c, const bool down, MMKeyFlags flags, uintptr pid) {
|
||||
convert characters to a keycode, but does not support adding modifier flags.
|
||||
It is only used in typeString().
|
||||
-- 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) {
|
||||
fputs("Could not create keyboard event.\n", stderr);
|
||||
return;
|
||||
|
@ -83,12 +83,13 @@
|
||||
/* Move the mouse to a specific point. */
|
||||
void moveMouse(MMPointInt32 point){
|
||||
#if defined(IS_MACOSX)
|
||||
CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
|
||||
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||
CGEventRef move = CGEventCreateMouseEvent(source, kCGEventMouseMoved,
|
||||
CGPointFromMMPointInt32(point), kCGMouseButtonLeft);
|
||||
|
||||
calculateDeltas(&move, point);
|
||||
|
||||
CGEventPost(kCGSessionEventTap, move);
|
||||
CGEventPost(kCGHIDEventTap, move);
|
||||
CFRelease(move);
|
||||
#elif defined(USE_X11)
|
||||
Display *display = XGetMainDisplay();
|
||||
@ -103,12 +104,13 @@ 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,
|
||||
CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
|
||||
CGEventRef drag = CGEventCreateMouseEvent(source, dragType,
|
||||
CGPointFromMMPointInt32(point), (CGMouseButton)button);
|
||||
|
||||
calculateDeltas(&drag, point);
|
||||
|
||||
CGEventPost(kCGSessionEventTap, drag);
|
||||
CGEventPost(kCGHIDEventTap, drag);
|
||||
CFRelease(drag);
|
||||
#else
|
||||
moveMouse(point);
|
||||
@ -145,9 +147,10 @@ void toggleMouse(bool down, MMMouseButton button) {
|
||||
#if defined(IS_MACOSX)
|
||||
const CGPoint currentPos = CGPointFromMMPointInt32(location());
|
||||
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);
|
||||
#elif defined(USE_X11)
|
||||
Display *display = XGetMainDisplay();
|
||||
|
Loading…
Reference in New Issue
Block a user