Skip to content

(nut-tree/nut.js#152) Switched to using a private event source and kC… #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/macos/keypress.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ void toggleKeyCode(MMKeyCode code, const bool down, MMKeyFlags flags)
}
else
{
CGEventRef keyEvent = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)code, down);
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStatePrivate);
CGEventRef keyEvent = CGEventCreateKeyboardEvent(src, (CGKeyCode)code, down);
assert(keyEvent != NULL);

CGEventSetType(keyEvent, down ? kCGEventKeyDown : kCGEventKeyUp);
CGEventSetFlags(keyEvent, flags);
CGEventPost(kCGSessionEventTap, keyEvent);
CGEventPost(kCGHIDEventTap, keyEvent);
CFRelease(keyEvent);
CFRelease(src);
}
}

Expand Down Expand Up @@ -89,7 +90,8 @@ void toggleUnicodeKey(unsigned long ch, const bool down)
* convert characters to a keycode, but does not support adding modifier
* flags. It is therefore only used in typeString() and typeStringDelayed()
* -- if you need modifier keys, use the above functions instead. */
CGEventRef keyEvent = CGEventCreateKeyboardEvent(NULL, 0, down);
CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStatePrivate);
CGEventRef keyEvent = CGEventCreateKeyboardEvent(src, 0, down);
if (keyEvent == NULL)
{
fputs("Could not create keyboard event.\n", stderr);
Expand All @@ -110,8 +112,9 @@ void toggleUnicodeKey(unsigned long ch, const bool down)
CGEventKeyboardSetUnicodeString(keyEvent, 1, &ch);
}

CGEventPost(kCGSessionEventTap, keyEvent);
CGEventPost(kCGHIDEventTap, keyEvent);
CFRelease(keyEvent);
CFRelease(src);
}

void toggleUniKey(char c, const bool down)
Expand Down