Re: Keystrokes for non-ascii letters
Re: Keystrokes for non-ascii letters
- Subject: Re: Keystrokes for non-ascii letters
- From: Dave DeLong <email@hidden>
- Date: Sat, 29 Nov 2008 11:00:40 -0700
An off-list reply pointed this one out to me as well, and I've been
playing with it. But I have some more roadblocks:
My server app is an agent application (it only runs from the
menubar). My preliminary tests show that posting keyboard events this
way to another application only result in a system beep. Of course,
that beep might be because I have the windowNumber hard set to 0.
When it's my own application that receives the event (I have a
textfield that's first responder), then it works perfectly.
So my questions are:
Can this be used for posting events that would get picked up by other
applications?
If it can, what should I do for the windowNumber?
Thanks a bunch,
Dave
On 29 Nov, 2008, at 10:41 AM, Ricky Sharp wrote:
As part of an automated testing framework, I generate individual
Unicode keyboard events like this:
- (void)postUnicodeKeyboardEvent_II:(unichar)aUnicodeCharacter
{
unichar theCharacters[1];
theCharacters[0] = aUnicodeCharacter;
NSString* theString = [[NSString alloc]
initWithCharacters:theCharacters length:1];
int theWindowNumber = [[applicationController_II contentWindow_II]
windowNumber];
NSEvent* theKeyboardEvent =
[NSEvent keyEventWithType:NSKeyDown location:NSMakePoint (0, 0)
modifierFlags:0 timestamp:0
windowNumber:theWindowNumber context:nil
characters:theString charactersIgnoringModifiers:nil
isARepeat:NO keyCode:0];
[NSApp postEvent:theKeyboardEvent atStart:NO];
}
In my case, I never needed to set the modifier flags, but you can
easily pass in whatever you need to above. And, depending on what
modifiers you're working with, make sure to properly set the
charactersIgnoringModifiers: param as well.
_______________________________________________
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