Re: Character to Keycode
Re: Character to Keycode
- Subject: Re: Character to Keycode
- From: Ricky Sharp <email@hidden>
- Date: Mon, 19 Mar 2007 15:30:23 -0500
On Mar 19, 2007, at 2:35 PM, Daniel Tse wrote:
Can someone please point me to how a person can convert a string
into a string of keycodes? Do I have to create a lookup table? I'm
trying to use something like the CGPostKeyboardEvent for my
accessibility app except the user can store up strings and then
post the entire string. I don't want to have the user memorize all
the keycodes for "Dear Mom,"... what is the proper approach? My
users are also bilingual (Canadian - French/English). I would be
happy with English but it'd be nice to do other languages with
their accents as well.
Am I missing a method? I think I have to break the string down into
individual characters and then convert each character to a
keycode... is that right? How do I go from character to keycode?
This is what I do in a Cocoa app (it's part of my automated testing
framework):
- (void)postUnicodeKeyboardEvent:(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];
}
Examples:
[self postUnicodeKeyboardEvent:NSEnterCharacter];
[self postUnicodeKeyboardEvent:0x4E03]; // Chinese '7'
Here, I'm just taking any unicode value and posting that (I don't
work at all with keycodes). If your input is a string, you can loop
over each character and post the individual chars. Or, in the
keyEventWithType: API above, notice that the characters: parameter is
a string (NSString/CFString) so you can probably (within reason) post
all characters at once.
If you're not using Cocoa, I'm sure there's an equivalent to the code
above.
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Accessibility-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden