From 5ffa64991b92fc1cf701adccdd3265f54e50b587 Mon Sep 17 00:00:00 2001 From: ghaushe Date: Wed, 5 Feb 2003 20:19:07 +0000 Subject: [PATCH] Correctly detect button presses on keyboards with alternate key mappings. This may fix the key-mapping issues Mac users have reported git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@688 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/ChangeLog | 2 ++ sc2/src/sc2code/libs/input/sdl/input.c | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/sc2/ChangeLog b/sc2/ChangeLog index 69a7c7efd..4e1f64bf0 100644 --- a/sc2/ChangeLog +++ b/sc2/ChangeLog @@ -1,4 +1,6 @@ Changes towards version 0.2: +- Correctly deal with multiply-mapped keys. This may fix some keys + not being detected correctly on the Mac as well - PBlue - OpenGL mode now fully supports partial screen updates -Mika - Fixed melee ship selection-box bugs -fOSSiL - Added a 4th button to starcon.key 'Esc' now emergency-escapes -PBlue diff --git a/sc2/src/sc2code/libs/input/sdl/input.c b/sc2/src/sc2code/libs/input/sdl/input.c index 22a9a68c2..89923bc06 100644 --- a/sc2/src/sc2code/libs/input/sdl/input.c +++ b/sc2/src/sc2code/libs/input/sdl/input.c @@ -34,6 +34,7 @@ static SWORD **JoyaxisValues = 0; static BOOLEAN (* PauseFunc) (void) = 0; static BOOLEAN InputInitialized = FALSE; +UWORD UNICODEToKBD (UNICODE which_key); UNICODE PauseKey = 0; UNICODE ExitKey = 0; @@ -111,25 +112,27 @@ void ProcessKeyboardEvent(const SDL_Event *Event) { SDLKey k = Event->key.keysym.sym; + UNICODE map_key; if (!InputInitialized) return; if (Event->type == SDL_KEYDOWN) { if (Event->key.keysym.unicode != 0) - kbdbuf[kbdtail] = (UNICODE) Event->key.keysym.unicode; + map_key = (UNICODE) Event->key.keysym.unicode; else - kbdbuf[kbdtail] = KBDToUNICODE(k); + map_key = KBDToUNICODE(k); + kbdbuf[kbdtail] = map_key; kbdtail = (kbdtail + 1) & (KBDBUFSIZE - 1); if (kbdtail == kbdhead) kbdhead = (kbdhead + 1) & (KBDBUFSIZE - 1); - if (KBDToUNICODE(k) == AbortKey) + if (map_key == AbortKey) exit(0); - KeyboardDown[k] |= 0x3; + KeyboardDown[UNICODEToKBD (map_key)] |= 0x3; } else { - KeyboardDown[k] &= (~0x1); + KeyboardDown[UNICODEToKBD (KBDToUNICODE (k))] &= (~0x1); } }