• 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: Eric Schlegel <email@hidden>
  • Date: Sat, 29 Nov 2008 08:58:33 -0800


On Nov 29, 2008, at 8:26 AM, Dave DeLong wrote:

Hey everyone,

I'm working on a client/server application. The client sends tiny "Event" objects to the server that can contain an NSString of a letter or short sequence of letters (up to about 4). What I'm trying to do is figure out how the server can perform the keypress(es) to get that letter (or sequence).


I know that I could use CGEventCreateKeyboardEvent, but that requires me to know the precise keycode for the letter. If I were limited to just ASCII 0-127, that wouldn't be so bad. But I could also be getting things like "é" or "£" and so on. I'd rather not hard code in every keystroke combination. =)

In general, this is difficult, because keyboard translation occurs via a semi-programmable state machine (the 'uchr' resource). So effectively you either need to run the state machine backwards, or start with each possible input keycode and modifiers combination, run the state machine forwards to produce the output character and use that to generate a table of what inputs produce what outputs.


My last idea is to put it on the clipboard and paste it in by simulating a command-v keystroke. The only problem with this is that command-v doesn't mean paste on all keyboards.

Do any of you have any ideas on how I can type arbitrary UTF8 characters programmatically?

You might look at CGKeyboardEventSetUnicodeString, although that won't help you to simulate command key sequences, because you can't set modifiers using that API.


You might also look at using the Accessibility API to explicit select the Paste menu item, rather than trying to simulate a keypress that would invoke the Paste menu item.

-eric

_______________________________________________

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


References: 
 >Keystrokes for non-ascii letters (From: Dave DeLong <email@hidden>)

  • Prev by Date: Re: Text blurred in application
  • Next by Date: Re: CALayer containing a view
  • Previous by thread: Keystrokes for non-ascii letters
  • Next by thread: Re: Keystrokes for non-ascii letters
  • Index(es):
    • Date
    • Thread