Hello list,
if this topic should be posted elsewhere, I'll gladly ask the question there.
My application send keyboard events to the system to simulate copy/paste and
other sorts of behaviour.
This works well as far as I can tell, but I'm running into a hiccup.
The code that sends events is this (more or less as you'd expect)
My current setup is 10.10 SDK, 10.8 deployment target and the described
misbehaviour is observable unter 10.9.
- (void)sendPressKey:(CGKeyCode)keyCode modifierFlags:(CGEventFlags)flags {
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);
CGEventSetFlags(releaseKey, 0);
/* Set the modifiers to the ones we want */
CGEventSetFlags(pressKey,flags);
CGEventSetFlags(releaseKey, flags);
/* Send the event */
NSLog(@"Seding %@", self);
CGEventPost(kCGHIDEventTap, pressKey);
usleep(0.05 * NSEC_PER_MSEC);
CGEventPost(kCGHIDEventTap, releaseKey);
CFRelease(pressKey);
CFRelease(releaseKey);
CFRelease(eventSource);
}
This works as expected when run in debug mode. But when I compile for release
and run, all the key codes work except Tab.
If Tab should be sent, I see a key code 0x5f being recorded. In debug the Tab
correctly gets sent as 0x30. My code always creates the keyboard event with the
correct modifiers (none) and key code for tab (0x30), so the code does not
change in debug or release but I've no clue, why I see this behaviour. Even
more so, I cannot pin it down why only in release.
Any suggestion as to why this is happening is highly appreciated.
Regarding the sleep in there, this was added by a contributor to make it wokr
under Yosemite.
___m i c h a e l s t a r k e____
geschäftsführer
HicknHack Software GmbH
www.hicknhack-software.com
___k o n t a k t____
+49 (170) 3686136
[email protected]
___H i c k n H a c k S o f t w a r e G m b H____
geschäftsführer - maik lathan | andreas reischuck | michael starke
bayreuther straße 32
01187 dresden
amtsgericht dresden HRB 30351
sitz - dresden
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]