From 4166327919c2df2026dcbfb195b88323808a37cc Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 8 Nov 2012 13:35:48 +0000 Subject: [PATCH] Fix some special keys, specifically backspace (it was mismapped to delete) --- panda/src/cocoadisplay/cocoaGraphicsWindow.h | 2 +- panda/src/cocoadisplay/cocoaGraphicsWindow.mm | 34 +++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/panda/src/cocoadisplay/cocoaGraphicsWindow.h b/panda/src/cocoadisplay/cocoaGraphicsWindow.h index 1a59265ae4..6fdc2a4497 100644 --- a/panda/src/cocoadisplay/cocoaGraphicsWindow.h +++ b/panda/src/cocoadisplay/cocoaGraphicsWindow.h @@ -80,7 +80,7 @@ protected: private: NSImage *load_image(const Filename &filename); - ButtonHandle map_function_key(unsigned short keycode); + ButtonHandle map_key(unsigned short keycode); private: NSWindow *_window; diff --git a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm index 8934a39da0..00ab842f3e 100644 --- a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm +++ b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm @@ -1555,30 +1555,23 @@ handle_key_event(NSEvent *event) { nassertv([str length] == 1); unichar c = [str characterAtIndex: 0]; - ButtonHandle button; + ButtonHandle button = map_key(c); - if (c >= 0xF700 && c < 0xF900) { - // Special function keys. - button = map_function_key(c); - - } else if (c == 0x3) { - button = KeyboardButton::enter(); - - } else { - // If a down event, process as keystroke too. + if (c < 0xF700 || c >= 0xF900) { + // If a down event and not a special function key, + // process it as keystroke as well. if ([event type] == NSKeyDown) { NSString *origstr = [event characters]; c = [str characterAtIndex: 0]; _input_devices[0].keystroke(c); } + } + if (button == ButtonHandle::none()) { // That done, continue trying to find out the button handle. if ([str canBeConvertedToEncoding: NSASCIIStringEncoding]) { // Nhm, ascii character perhaps? button = KeyboardButton::ascii_key([str cStringUsingEncoding: NSASCIIStringEncoding]); - - } else { - button = ButtonHandle::none(); } } @@ -1694,13 +1687,24 @@ handle_wheel_event(double x, double y) { } //////////////////////////////////////////////////////////////////// -// Function: CocoaGraphicsWindow::map_function_key +// Function: CocoaGraphicsWindow::map_key // Access: Private // Description: //////////////////////////////////////////////////////////////////// ButtonHandle CocoaGraphicsWindow:: -map_function_key(unsigned short keycode) { +map_key(unsigned short keycode) { switch (keycode) { + case NSEnterCharacter: + return KeyboardButton::enter(); + case NSBackspaceCharacter: + case NSDeleteCharacter: + // NSDeleteCharacter fires when I press backspace. + return KeyboardButton::backspace(); + case NSTabCharacter: + case NSBackTabCharacter: + // BackTabCharacter is sent when shift-tab is used. + return KeyboardButton::tab(); + case NSUpArrowFunctionKey: return KeyboardButton::up(); case NSDownArrowFunctionKey: