ref: c5a4f04bc21825a0bdd59bef804229389a7a4ce1
parent: cebecf16cc349650bf2a9b20f24b2eac6372e07b
author: Simon Howard <[email protected]>
date: Fri Mar 9 07:35:18 EST 2007
Fix discrepancy between Doom and setup program when prompting for keys. Add the ability to enable/disable key mappings so that the raw key can be read in setup, exactly the same way that it is in Doom. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 846
--- a/setup/txt_keyinput.c
+++ b/setup/txt_keyinput.c
@@ -44,6 +44,11 @@
*key_input->variable = key;
TXT_EmitSignal(key_input, "set");
TXT_CloseWindow(window);
+
+ // Re-enable key mappings now that we have the key
+
+ TXT_EnableKeyMapping(1);
+
return 1;
}
else
@@ -69,6 +74,10 @@
TXT_SetWidgetAlign(label, TXT_HORIZ_CENTER);
TXT_SetKeyListener(window, KeyPressCallback, key_input);
+
+ // Disable key mappings while we prompt for the key press
+
+ TXT_EnableKeyMapping(0);
}
static void TXT_KeyInputSizeCalc(TXT_UNCAST_ARG(key_input))
--- a/textscreen/txt_main.c
+++ b/textscreen/txt_main.c
@@ -44,6 +44,7 @@
static SDL_Surface *screen;
static unsigned char *screendata;
+static int key_mapping = 1;
//#define TANGO
@@ -229,73 +230,88 @@
{
switch(sym->sym)
{
- case SDLK_LEFT: return KEY_LEFTARROW;
- case SDLK_RIGHT: return KEY_RIGHTARROW;
- case SDLK_DOWN: return KEY_DOWNARROW;
- case SDLK_UP: return KEY_UPARROW;
- case SDLK_ESCAPE: return KEY_ESCAPE;
- case SDLK_RETURN: return KEY_ENTER;
- case SDLK_TAB: return KEY_TAB;
- case SDLK_F1: return KEY_F1;
- case SDLK_F2: return KEY_F2;
- case SDLK_F3: return KEY_F3;
- case SDLK_F4: return KEY_F4;
- case SDLK_F5: return KEY_F5;
- case SDLK_F6: return KEY_F6;
- case SDLK_F7: return KEY_F7;
- case SDLK_F8: return KEY_F8;
- case SDLK_F9: return KEY_F9;
- case SDLK_F10: return KEY_F10;
- case SDLK_F11: return KEY_F11;
- case SDLK_F12: return KEY_F12;
-
- case SDLK_BACKSPACE: return KEY_BACKSPACE;
- case SDLK_DELETE: return KEY_DEL;
+ case SDLK_LEFT: return KEY_LEFTARROW;
+ case SDLK_RIGHT: return KEY_RIGHTARROW;
+ case SDLK_DOWN: return KEY_DOWNARROW;
+ case SDLK_UP: return KEY_UPARROW;
+ case SDLK_ESCAPE: return KEY_ESCAPE;
+ case SDLK_RETURN: return KEY_ENTER;
+ case SDLK_TAB: return KEY_TAB;
+ case SDLK_F1: return KEY_F1;
+ case SDLK_F2: return KEY_F2;
+ case SDLK_F3: return KEY_F3;
+ case SDLK_F4: return KEY_F4;
+ case SDLK_F5: return KEY_F5;
+ case SDLK_F6: return KEY_F6;
+ case SDLK_F7: return KEY_F7;
+ case SDLK_F8: return KEY_F8;
+ case SDLK_F9: return KEY_F9;
+ case SDLK_F10: return KEY_F10;
+ case SDLK_F11: return KEY_F11;
+ case SDLK_F12: return KEY_F12;
- case SDLK_PAUSE: return KEY_PAUSE;
+ case SDLK_BACKSPACE: return KEY_BACKSPACE;
+ case SDLK_DELETE: return KEY_DEL;
- case SDLK_KP_EQUALS: return KEY_EQUALS;
+ case SDLK_PAUSE: return KEY_PAUSE;
- case SDLK_LSHIFT:
- case SDLK_RSHIFT:
- return KEY_RSHIFT;
+ case SDLK_KP_EQUALS: return KEY_EQUALS;
- case SDLK_LCTRL:
- case SDLK_RCTRL:
- return KEY_RCTRL;
-
- case SDLK_LALT:
- case SDLK_LMETA:
- case SDLK_RALT:
- case SDLK_RMETA:
- return KEY_RALT;
+ case SDLK_LSHIFT:
+ case SDLK_RSHIFT:
+ return KEY_RSHIFT;
- case SDLK_CAPSLOCK: return KEY_CAPSLOCK;
- case SDLK_SCROLLOCK: return KEY_SCRLCK;
+ case SDLK_LCTRL:
+ case SDLK_RCTRL:
+ return KEY_RCTRL;
- case SDLK_KP0: return KEYP_0;
- case SDLK_KP1: return KEYP_1;
- case SDLK_KP2: return KEYP_2;
- case SDLK_KP3: return KEYP_3;
- case SDLK_KP4: return KEYP_4;
- case SDLK_KP5: return KEYP_5;
- case SDLK_KP6: return KEYP_6;
- case SDLK_KP7: return KEYP_7;
- case SDLK_KP8: return KEYP_8;
- case SDLK_KP9: return KEYP_9;
+ case SDLK_LALT:
+ case SDLK_LMETA:
+ case SDLK_RALT:
+ case SDLK_RMETA:
+ return KEY_RALT;
- case SDLK_HOME: return KEY_HOME;
- case SDLK_INSERT: return KEY_INS;
- case SDLK_END: return KEY_END;
- case SDLK_PAGEUP: return KEY_PGUP;
- case SDLK_PAGEDOWN: return KEY_PGDN;
- case SDLK_KP_MULTIPLY: return KEYP_MULTIPLY;
- case SDLK_KP_PLUS: return KEYP_PLUS;
- case SDLK_KP_MINUS: return KEYP_MINUS;
- case SDLK_KP_DIVIDE: return KEYP_DIVIDE;
+ case SDLK_CAPSLOCK: return KEY_CAPSLOCK;
+ case SDLK_SCROLLOCK: return KEY_SCRLCK;
- default: return sym->unicode;
+ case SDLK_KP0: return KEYP_0;
+ case SDLK_KP1: return KEYP_1;
+ case SDLK_KP2: return KEYP_2;
+ case SDLK_KP3: return KEYP_3;
+ case SDLK_KP4: return KEYP_4;
+ case SDLK_KP5: return KEYP_5;
+ case SDLK_KP6: return KEYP_6;
+ case SDLK_KP7: return KEYP_7;
+ case SDLK_KP8: return KEYP_8;
+ case SDLK_KP9: return KEYP_9;
+
+ case SDLK_HOME: return KEY_HOME;
+ case SDLK_INSERT: return KEY_INS;
+ case SDLK_END: return KEY_END;
+ case SDLK_PAGEUP: return KEY_PGUP;
+ case SDLK_PAGEDOWN: return KEY_PGDN;
+ case SDLK_KP_MULTIPLY: return KEYP_MULTIPLY;
+ case SDLK_KP_PLUS: return KEYP_PLUS;
+ case SDLK_KP_MINUS: return KEYP_MINUS;
+ case SDLK_KP_DIVIDE: return KEYP_DIVIDE;
+
+ default: break;
}
+
+ // Returned value is different, depending on whether key mapping is
+ // enabled. Key mapping is preferable most of the time, for typing
+ // in text, etc. However, when we want to read raw keyboard codes
+ // for the setup keyboard configuration dialog, we want the raw
+ // key code.
+
+ if (key_mapping)
+ {
+ return sym->unicode;
+ }
+ else
+ {
+ return tolower(sym->sym);
+ }
}
@@ -495,5 +511,10 @@
SDL_Delay(1);
}
}
+}
+
+void TXT_EnableKeyMapping(int enable)
+{
+ key_mapping = enable;
}
--- a/textscreen/txt_main.h
+++ b/textscreen/txt_main.h
@@ -104,5 +104,10 @@
void TXT_Sleep(int timeout);
+// Controls whether keys are returned from TXT_GetChar based on keyboard
+// mapping, or raw key code.
+
+void TXT_EnableKeyMapping(int enable);
+
#endif /* #ifndef TXT_MAIN_H */