From c2985d2faab043538df713260ece75c9a3f3eac2 Mon Sep 17 00:00:00 2001 From: michael starke Date: Tue, 2 Dec 2014 20:53:35 +0100 Subject: [PATCH] Using private event source for keyboard events --- MacPass/MPAutotypeCommand.m | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/MacPass/MPAutotypeCommand.m b/MacPass/MPAutotypeCommand.m index 8b8f25e6..27adfa7c 100644 --- a/MacPass/MPAutotypeCommand.m +++ b/MacPass/MPAutotypeCommand.m @@ -311,8 +311,13 @@ } - (void)sendPressKey:(CGKeyCode)keyCode modifierFlags:(CGEventFlags)flags { - CGEventRef pressKey = CGEventCreateKeyboardEvent (NULL, keyCode, YES); - CGEventRef releaseKey = CGEventCreateKeyboardEvent (NULL, keyCode, NO); + + CGEventSourceRef eventSource = CGEventSourceCreate(kCGEventSourceStatePrivate); + if(NULL == eventSource) { + return; // We could not create our own source, abort! + } + CGEventRef pressKey = CGEventCreateKeyboardEvent (eventSource, keyCode, YES); + CGEventRef releaseKey = CGEventCreateKeyboardEvent (eventSource, keyCode, NO); /* The modifer Masks might be set, reset them */ CGEventSetFlags(pressKey,0); @@ -322,12 +327,14 @@ CGEventSetFlags(releaseKey, flags); /* Send the event */ - CGEventPost(kCGSessionEventTap, pressKey); + NSLog(@"Seding %@", self); + CGEventPost(kCGHIDEventTap, pressKey); usleep(0.05 * NSEC_PER_MSEC); - CGEventPost(kCGSessionEventTap, releaseKey); + CGEventPost(kCGHIDEventTap, releaseKey); CFRelease(pressKey); CFRelease(releaseKey); + CFRelease(eventSource); } - (void)sendPasteKeyCode {