+ long retval = 0;
+
+ if ([event type] != NSFlagsChanged)
+ {
+ NSString* s = [event charactersIgnoringModifiers];
+ // backspace char reports as delete w/modifiers for some reason
+ if ([s length] == 1)
+ {
+ switch ( [s characterAtIndex:0] )
+ {
+ // backspace key
+ case 0x7F :
+ case 8 :
+ retval = WXK_BACK;
+ break;
+ case NSUpArrowFunctionKey :
+ retval = WXK_UP;
+ break;
+ case NSDownArrowFunctionKey :
+ retval = WXK_DOWN;
+ break;
+ case NSLeftArrowFunctionKey :
+ retval = WXK_LEFT;
+ break;
+ case NSRightArrowFunctionKey :
+ retval = WXK_RIGHT;
+ break;
+ case NSInsertFunctionKey :
+ retval = WXK_INSERT;
+ break;
+ case NSDeleteFunctionKey :
+ retval = WXK_DELETE;
+ break;
+ case NSHomeFunctionKey :
+ retval = WXK_HOME;
+ break;
+ // case NSBeginFunctionKey :
+ // retval = WXK_BEGIN;
+ // break;
+ case NSEndFunctionKey :
+ retval = WXK_END;
+ break;
+ case NSPageUpFunctionKey :
+ retval = WXK_PAGEUP;
+ break;
+ case NSPageDownFunctionKey :
+ retval = WXK_PAGEDOWN;
+ break;
+ case NSHelpFunctionKey :
+ retval = WXK_HELP;
+ break;
+ default:
+ int intchar = [s characterAtIndex: 0];
+ if ( intchar >= NSF1FunctionKey && intchar <= NSF24FunctionKey )
+ retval = WXK_F1 + (intchar - NSF1FunctionKey );
+ break;
+ }
+ }
+ }
+
+ // Some keys don't seem to have constants. The code mimics the approach
+ // taken by WebKit. See:
+ // http://trac.webkit.org/browser/trunk/WebCore/platform/mac/KeyEventMac.mm
+ switch( [event keyCode] )