From 7914234b2601eeb2c6563462649f269e8cfbb16c Mon Sep 17 00:00:00 2001 From: Cyril Dubet Date: Wed, 5 Apr 2023 01:21:41 +0200 Subject: [PATCH] Fix key code names for ISO keyboard layouts (cherry picked from commit 60dcaff7eb25a01c9c87a5fed335b29a5625b95b) --- src/video/cocoa/SDL_cocoakeyboard.m | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/video/cocoa/SDL_cocoakeyboard.m b/src/video/cocoa/SDL_cocoakeyboard.m index f085ccced3..9c49deb6ac 100644 --- a/src/video/cocoa/SDL_cocoakeyboard.m +++ b/src/video/cocoa/SDL_cocoakeyboard.m @@ -280,6 +280,17 @@ UpdateKeymap(SDL_VideoData *data, SDL_bool send_event) continue; } + /* + * Swap the scancode for these two wrongly translated keys + * UCKeyTranslate() function does not do its job properly for ISO layout keyboards, where the key '@', + * which is located in the top left corner of the keyboard right under the Escape key, and the additional + * key '<', which is on the right of the Shift key, are inverted + */ + if ((scancode == SDL_SCANCODE_NONUSBACKSLASH || scancode == SDL_SCANCODE_GRAVE) && KBGetLayoutType(LMGetKbdType()) == kKeyboardISO) { + /* see comments in scancodes_darwin.h */ + scancode = (SDL_Scancode)((SDL_SCANCODE_NONUSBACKSLASH + SDL_SCANCODE_GRAVE) - scancode); + } + dead_key_state = 0; err = UCKeyTranslate ((UCKeyboardLayout *) chr_data, i, kUCKeyActionDown, @@ -394,7 +405,7 @@ Cocoa_HandleKeyEvent(_THIS, NSEvent *event) #endif if ((scancode == 10 || scancode == 50) && KBGetLayoutType(LMGetKbdType()) == kKeyboardISO) { - /* see comments in SDL_cocoakeys.h */ + /* see comments in scancodes_darwin.h */ scancode = 60 - scancode; }