• 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 (SOLVED)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Keystrokes for non-ascii letters (SOLVED)


  • Subject: Re: Keystrokes for non-ascii letters (SOLVED)
  • From: Dave DeLong <email@hidden>
  • Date: Sat, 29 Nov 2008 17:02:31 -0700

Fantastic! I've gotten it to work, and it works beautifully! Thank you, James (and everyone else) for helping me with this.

For archival purposes, here's my code:

CGEventSourceRef eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
CGEventRef keyEventDown = CGEventCreateKeyboardEvent(eventSource, 0, true);
NSString * characters = ;//some UTF16 string acquired from somewhere. in my case, an NSData object
UniChar buffer;
for (int i = 0; i < [characters length]; i++) {
[characters getCharacters:&buffer range:NSMakeRange(i, 1)];
keyEventDown = CGEventCreateKeyboardEvent(eventSource, 1, true);
CGEventKeyboardSetUnicodeString(keyEventDown, 1, &buffer);
CGEventPost(kCGHIDEventTap, keyEventDown);
CFRelease(keyEventDown);
}
CFRelease(eventSource);


Thanks again for all your help!

Dave

On 29 Nov, 2008, at 3:10 PM, James W. Walker wrote:

Your source file is probably encoded as UTF-8, so the pound character is getting interpreted as 2 bytes of UTF-8, not a single UTF-16 character. Don't try to enter Unicode directly in your source.

Lastly, I'm not sure how I can convert my NSString into a UniChar array (which is what the function wants).

See the getCharacters: method.
_______________________________________________

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 (SOLVED)
      • From: Jean-Daniel Dupas <email@hidden>
References: 
 >Keystrokes for non-ascii letters (From: Dave DeLong <email@hidden>)
 >Re: Keystrokes for non-ascii letters (From: Ricky Sharp <email@hidden>)
 >Re: Keystrokes for non-ascii letters (From: Dave DeLong <email@hidden>)
 >Re: Keystrokes for non-ascii letters (From: Bill Bumgarner <email@hidden>)
 >Re: Keystrokes for non-ascii letters (From: Dave DeLong <email@hidden>)
 >Re: Keystrokes for non-ascii letters (From: "James W. Walker" <email@hidden>)
 >Re: Keystrokes for non-ascii letters (From: Dave DeLong <email@hidden>)
 >Re: Keystrokes for non-ascii letters (From: "James W. Walker" <email@hidden>)

  • Prev by Date: Re: reading a PDF
  • Next by Date: RE: Simple Core Animation Problem
  • Previous by thread: Re: Keystrokes for non-ascii letters
  • Next by thread: Re: Keystrokes for non-ascii letters (SOLVED)
  • Index(es):
    • Date
    • Thread