On Nov 29, 2008, at 1:03 PM, Dave DeLong wrote:

More questions!  (wheeee  =) )

I've abandoned the NSEvent approach, although it would've been nice if it had worked, and am now trying CGEventKeyboardSetUnicodeString. Here's my code:

CGEventSourceRef eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState); CGEventRef keyEventDown = CGEventCreateKeyboardEvent(eventSource, 0, true); UniChar buffer = '£'; //that's a pound (the currency) sign for all you without unicode support in your email
        CGEventKeyboardSetUnicodeString(keyEventDown, 1, &buffer);
        CGEventPost(kCGHIDEventTap, keyEventDown);
        CFRelease(keyEventDown);

First off, when building it, I get a warning on the "buffer = '£';" line, that it's a "multi-character character constant". What does that mean? Then, when I actually run it, I don't get the pound sign, but get some Asian character that looks like a cross between a camping stove and a two-story house.


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.


I've been all over Google and the various list archives for more information on CGEventKeyboardSetUnicodeString, but have found nothing helpful.


It didn't actually work for both Cocoa and Carbon apps until some recent update of Leopard, so probably nobody has been using it.



On 29 Nov, 2008, at 1:27 PM, James W. Walker wrote:

Eric Schlegel already suggested CGEventKeyboardSetUnicodeString, although he misspelled it. As long as you can require 10.5.5 or later, that should do the trick.

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to