summaryrefslogtreecommitdiff
path: root/textscreen/txt_sdl.c
diff options
context:
space:
mode:
Diffstat (limited to 'textscreen/txt_sdl.c')
-rw-r--r--textscreen/txt_sdl.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/textscreen/txt_sdl.c b/textscreen/txt_sdl.c
index 5ae151e9..767c9b3e 100644
--- a/textscreen/txt_sdl.c
+++ b/textscreen/txt_sdl.c
@@ -63,6 +63,8 @@ static int key_mapping = 1;
static TxtSDLEventCallbackFunc event_callback;
static void *event_callback_data;
+static int modifier_state[TXT_NUM_MODIFIERS];
+
// Font we are using:
static txt_font_t *font;
@@ -493,6 +495,48 @@ static int MouseHasMoved(void)
}
}
+// Examine a key press/release and update the modifier key state
+// if necessary.
+
+static void UpdateModifierState(SDL_keysym *sym, int pressed)
+{
+ txt_modifier_t mod;
+
+ switch (sym->sym)
+ {
+ case SDLK_LSHIFT:
+ case SDLK_RSHIFT:
+ mod = TXT_MOD_SHIFT;
+ break;
+
+ case SDLK_LCTRL:
+ case SDLK_RCTRL:
+ mod = TXT_MOD_CTRL;
+ break;
+
+ case SDLK_LALT:
+ case SDLK_RALT:
+#if !SDL_VERSION_ATLEAST(1, 3, 0)
+ case SDLK_LMETA:
+ case SDLK_RMETA:
+#endif
+ mod = TXT_MOD_ALT;
+ break;
+
+ default:
+ return;
+ }
+
+ if (pressed)
+ {
+ ++modifier_state[mod];
+ }
+ else
+ {
+ --modifier_state[mod];
+ }
+}
+
signed int TXT_GetChar(void)
{
SDL_Event ev;
@@ -522,8 +566,14 @@ signed int TXT_GetChar(void)
break;
case SDL_KEYDOWN:
+ UpdateModifierState(&ev.key.keysym, 1);
+
return TranslateKey(&ev.key.keysym);
+ case SDL_KEYUP:
+ UpdateModifierState(&ev.key.keysym, 0);
+ break;
+
case SDL_QUIT:
// Quit = escape
return 27;
@@ -542,6 +592,16 @@ signed int TXT_GetChar(void)
return -1;
}
+int TXT_GetModifierState(txt_modifier_t mod)
+{
+ if (mod < TXT_NUM_MODIFIERS)
+ {
+ return modifier_state[mod] > 0;
+ }
+
+ return 0;
+}
+
static const char *SpecialKeyName(int key)
{
switch (key)