|
|
Key Code translation?
|
|
|
|
Forum Regular
Join Date: Mar 2002
Location: Düsseldorf, Germany, Europe, Earth
Status:
Offline
|
|
Is there any quick way in Cocoa/ObjC to translate the Key Code, as returned by the keyCode method of an NSEvent, into the corresponding character, subject to the current keyboard setting? I don't have any key event hanging around, as I'm doing something like the Key Caps utility.
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
Call characters off the NSEvent instance.
HTH,
F-bacher
|
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Mar 2002
Location: Düsseldorf, Germany, Europe, Earth
Status:
Offline
|
|
Ghoser, unfortunately I don't have any instance of NSEvent handy. I'm trying to draw a virtual keyboard.
|
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Sep 2000
Location: Norfolk, Va
Status:
Offline
|
|
This seems a curious omission, but... it appears Apple does not have an NSEnterKey or NSReturnKey constant for the NSEvent class.
In fact, calling [theEvent characters] does not return anything for the former and simply returns an "r" for the latter. How can I use that to tell when the user presses enter or return?!
What's more, the keyCode method returns an integer specific to the keyboard connected, thus making it totally useless, right? It'll be different on each keyboard.
How can I tell when enter has been pressed? In my app, I already have my custom NSView set up as the first responder, and it calls its method when a key is pressed. Now I need a way to filter it down to just those two keys.
I have been boning up on the responder chain, NSApplication event handling, and keyboard interface control, but none of these are either helping or hindering me. It's simply undefined. any ideas?
Thanks.
|
you are not your signature
|
|
|
|
|
|
|
|
Junior Member
Join Date: Jun 2002
Location: Springfield
Status:
Offline
|
|
Perhaps I'm not following what you guys are looking for, but this works fine for me in my view subclass:
- (void)keyDown:(NSEvent *)theEvent
{
char c = [[theEvent characters] characterAtIndex:0];
if ( c == 0x03 )
NSLog( @"Backslash N" );
else if ( c == '\r' )
NSLog( @"Backslash R" );
else
NSLog( @"%c", c );
}
Check out the thread here - it's where I came up with 0x03 instead of '\n':
http://cocoa.mamasam.com/COCOADEV/2001/08/2/10806.php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|