Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I find a list of key codes for use with Cocoa's NSEvent class?

I'm looking for a comprehensive list of the available key codes that can be used with Cocoa's NSEvent class. The NSEvent class has a keyCode property, which is defined as unsigned short. The following code, when placed in an appropriate UI object, will echo the key codes as they are pressed:

- (void)keyDown:(NSEvent *)theEvent {     NSLog(@"%d", [theEvent keyCode]); } 

From this code, I can easily see which codes match certain keys, but I would like to find an official document somewhere that lists all of them. I expected Apple to have a header file somewhere that looked like this:

enum {     ...     NSKeyCodeLeftArrow = 123,     NSKeyCodeRightArrow = 124,     ... }; 

But if there is one, I have yet to find it.

like image 643
e.James Avatar asked Jan 17 '10 07:01

e.James


People also ask

What is a keyboard keycode?

Key codes are numeric values that correspond to physical keys on the keyboard but do not necessarily correspond to a particular character.

What is the keycode for arrow keys?

Arrow keys are only triggered by onkeydown , not onkeypress . The keycodes are: left = 37. up = 38.


1 Answers

Here you go. It's a map of all the virtual key-codes on the US extended keyboard layout, from the old Inside Macintosh: Text. Most of the key codes are still currently, although I suspect that the very newest Apple keyboards—those with media keys—may have changed a few of the function keys.

Note: ISO and non-extended keyboards may have different key codes for some keys. If you have such a keyboard, try Peter Maurer's Key Codes application. His site is down, so here's my copy.

like image 180
Peter Hosey Avatar answered Oct 05 '22 18:10

Peter Hosey