Re: Send Key Event to Focused Window
Re: Send Key Event to Focused Window
- Subject: Re: Send Key Event to Focused Window
- From: Bill Cheeseman <email@hidden>
- Date: Thu, 19 Jun 2008 06:15:22 -0400
- Thread-topic: Send Key Event to Focused Window
on 2008-06-19 3:46 AM, Daniel at email@hidden wrote:
> CGEventRef event = CGEventCreateKeyboardEvent(NULL, (CGKeyCode) 40, true);
> CGEventPost(kCGHIDEventTap, event);
I wouldn't expect you to get even the "k" character with that code by
itself. To type a character requires posting a key down event AND a key up
event with the same keycode. So add these two lines at the end of your
code:
CGEventSetType(event, kCGEventKeyDown);
CGEventPost(kCGHIDEventTap, event);
Or simply create a separate keyboard event with false in the keyDown
parameter and post it.
Also, you might have better luck with one of the other tap locations, such
as kCGSessionEventTap. I believe the kCGHIDEventTap location requires you to
run as root or it doesn't work.
To identify the valid keycodes for your keyboard, get one of the Key Code
utililties that are floating around on the Web. My free PreFab Event Taps
Testbench is one such, at <http://prefabsoftware.com/eventtapstestbench>.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
www.quecheesoftware.com
PreFab Software - www.prefabsoftware.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden