• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Keystrokes for non-ascii letters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Keystrokes for non-ascii letters
      • From: Bill Bumgarner <email@hidden>
References: 
 >Keystrokes for non-ascii letters (From: Dave DeLong <email@hidden>)
 >Re: Keystrokes for non-ascii letters (From: Ricky Sharp <email@hidden>)

  • Prev by Date: Re: Checking One Array Against Another
  • Next by Date: Re: Checking One Array Against Another
  • Previous by thread: Re: Keystrokes for non-ascii letters
  • Next by thread: Re: Keystrokes for non-ascii letters
  • Index(es):
    • Date
    • Thread