From 28f49ffd0b2d472f752bc122638ffde1705424f2 Mon Sep 17 00:00:00 2001 From: LD Date: Tue, 1 Sep 2020 20:25:18 +0200 Subject: [PATCH] cocoadisplay: Use [event charactersIgnoringModifiers] when UCKeyTranslate() can not translate the input key --- panda/src/cocoadisplay/cocoaGraphicsWindow.mm | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm index 49857a4d14..ace8a4973b 100644 --- a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm +++ b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm @@ -1762,6 +1762,19 @@ handle_key_event(NSEvent *event) { return; } + // If UCKeyTranslate could not map the key into a valid unicode character or + // reserved symbol (See NSEvent.h), it returns 0x10 as translated character. + // This happens e.g.e with the combination Fn+F1.. keys. + // In that case, as fallback, we use charactersIgnoringModifiers to retrieve + // the character without modifiers. + if (c == 0x10) { + NSString *str = [event charactersIgnoringModifiers]; + if (str == nil || [str length] != 1) { + return; + } + c = [str characterAtIndex: 0]; + } + ButtonHandle button = map_key(c); if (button == ButtonHandle::none()) {