From 31a8bfebb6c86aa84741739e12159557b2a4a602 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Mon, 27 Jan 2014 10:30:25 +0000 Subject: [PATCH] SDL: Fix "the issue where if you hold down a key and enter the console then release it that the key remains held down until you hit it again outside the console". git-svn-id: https://svn.eduke32.com/eduke32@4269 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/baselayer.h | 6 +++-- polymer/eduke32/build/src/baselayer.c | 8 +++++-- polymer/eduke32/build/src/config.c | 2 -- polymer/eduke32/build/src/osd.c | 6 ++--- polymer/eduke32/build/src/rawinput.c | 2 +- polymer/eduke32/build/src/sdlayer.c | 28 +++++++++++++++++++---- polymer/eduke32/build/src/winlayer.c | 2 +- 7 files changed, 39 insertions(+), 15 deletions(-) diff --git a/polymer/eduke32/build/include/baselayer.h b/polymer/eduke32/build/include/baselayer.h index f6b774f0d..f1345718c 100644 --- a/polymer/eduke32/build/include/baselayer.h +++ b/polymer/eduke32/build/include/baselayer.h @@ -82,14 +82,16 @@ extern void setvsync(int32_t sync); extern char inputdevices; // keys +#define KEYSTATUSSIZ 256 #define KEYFIFOSIZ 64 -extern char keystatus[256], keyfifo[KEYFIFOSIZ], keyfifoplc, keyfifoend; +extern char keystatus[KEYSTATUSSIZ], keyfifo[KEYFIFOSIZ], keyfifoplc, keyfifoend; extern char keyasciififo[KEYFIFOSIZ], keyasciififoplc, keyasciififoend; -extern char scantoasc[128], remap[256], key_names[256][24]; +extern char scantoasc[128], remap[KEYSTATUSSIZ], key_names[256][24]; extern int32_t remapinit; extern int32_t defaultres[][2]; +extern int32_t GetKey(int32_t key); extern void SetKey(int32_t key, int32_t state); // mouse diff --git a/polymer/eduke32/build/src/baselayer.c b/polymer/eduke32/build/src/baselayer.c index 3619576a0..7220d91df 100644 --- a/polymer/eduke32/build/src/baselayer.c +++ b/polymer/eduke32/build/src/baselayer.c @@ -10,9 +10,9 @@ // input char inputdevices=0; -char keystatus[256], keyfifo[KEYFIFOSIZ], keyfifoplc, keyfifoend; +char keystatus[KEYSTATUSSIZ], keyfifo[KEYFIFOSIZ], keyfifoplc, keyfifoend; char keyasciififo[KEYFIFOSIZ], keyasciififoplc, keyasciififoend; -char remap[256]; +char remap[KEYSTATUSSIZ]; int32_t remapinit=0; char key_names[256][24]; volatile int32_t mousex=0,mousey=0,mouseb=0,mouseabsx=0,mouseabsy=0; @@ -54,6 +54,10 @@ int32_t defaultres[][2] = }; +int32_t GetKey(int32_t key) +{ + return keystatus[remap[key]]; +} void SetKey(int32_t key, int32_t state) { keystatus[remap[key]] = state; diff --git a/polymer/eduke32/build/src/config.c b/polymer/eduke32/build/src/config.c index 46ac3496c..2a33fb938 100644 --- a/polymer/eduke32/build/src/config.c +++ b/polymer/eduke32/build/src/config.c @@ -70,8 +70,6 @@ extern char game_executable[BMAX_PATH]; extern int32_t fullscreen; extern char default_buildkeys[NUMBUILDKEYS]; static char *const keys = default_buildkeys; -extern char remap[256]; -extern int32_t remapinit; static int32_t default_grid=3; extern int32_t AmbienceToggle, MixRate; extern int32_t ParentalLock; diff --git a/polymer/eduke32/build/src/osd.c b/polymer/eduke32/build/src/osd.c index 651c400f1..c4a28b689 100644 --- a/polymer/eduke32/build/src/osd.c +++ b/polymer/eduke32/build/src/osd.c @@ -1217,7 +1217,7 @@ int32_t OSD_HandleChar(char ch) int32_t OSD_HandleScanCode(int32_t sc, int32_t press) { if ((osdflags & OSD_INITIALIZED) == 0) - return sc; + return 1; if (sc == osdkey) { @@ -1232,10 +1232,10 @@ int32_t OSD_HandleScanCode(int32_t sc, int32_t press) OSD_CaptureInput(osdscroll == 1); osdscrtime = getticks(); } - return 0; + return -1; } else if ((osdflags & OSD_CAPTURE) == 0) - return sc; + return 2; if (!press) { diff --git a/polymer/eduke32/build/src/rawinput.c b/polymer/eduke32/build/src/rawinput.c index 11e7aa0a5..d895ba8b1 100644 --- a/polymer/eduke32/build/src/rawinput.c +++ b/polymer/eduke32/build/src/rawinput.c @@ -145,7 +145,7 @@ static inline void RI_ProcessKeyboard(const RAWKEYBOARD *rkbd) KeyboardState[VKey] = 1 - (rkbd->Flags & RI_KEY_BREAK); - if (OSD_HandleScanCode(key, KeyboardState[VKey] != 0)) + if (OSD_HandleScanCode(key, KeyboardState[VKey] > 0)) { SetKey(key, KeyboardState[VKey] != 0); diff --git a/polymer/eduke32/build/src/sdlayer.c b/polymer/eduke32/build/src/sdlayer.c index 9c0400af5..d7f0073e6 100644 --- a/polymer/eduke32/build/src/sdlayer.c +++ b/polymer/eduke32/build/src/sdlayer.c @@ -2151,12 +2151,22 @@ int32_t handleevents(void) // printf("got key %d, %d\n",ev.key.keysym.scancode,code); // hook in the osd - if (OSD_HandleScanCode(code, (ev.key.type == SDL_KEYDOWN)) == 0) + if ((j = OSD_HandleScanCode(code, (ev.key.type == SDL_KEYDOWN))) <= 0) + { + if (j == -1) // osdkey + for (j = 0; j < KEYSTATUSSIZ; ++j) + if (GetKey(j)) + { + SetKey(j, 0); + if (keypresscallback) + keypresscallback(j, 0); + } break; + } if (ev.key.type == SDL_KEYDOWN) { - if (!keystatus[code]) + if (!GetKey(code)) { SetKey(code, 1); if (keypresscallback) @@ -2240,12 +2250,22 @@ int32_t handleevents(void) // hook in the osd // if (ev.type==SDL_KEYDOWN) // printf("got key SDLK %d (%s), trans 0x%x\n", ev.key.keysym.sym, SDL_GetKeyName(ev.key.keysym.sym), code); - if (OSD_HandleScanCode(code, (ev.key.type == SDL_KEYDOWN)) == 0) + if ((j = OSD_HandleScanCode(code, (ev.key.type == SDL_KEYDOWN))) <= 0) + { + if (j == -1) // osdkey + for (j = 0; j < KEYSTATUSSIZ; ++j) + if (GetKey(j)) + { + SetKey(j, 0); + if (keypresscallback) + keypresscallback(j, 0); + } break; + } if (ev.key.type == SDL_KEYDOWN) { - if (!keystatus[code]) + if (!GetKey(code)) { SetKey(code, 1); if (keypresscallback) diff --git a/polymer/eduke32/build/src/winlayer.c b/polymer/eduke32/build/src/winlayer.c index e8480bd1d..d79add9b5 100644 --- a/polymer/eduke32/build/src/winlayer.c +++ b/polymer/eduke32/build/src/winlayer.c @@ -944,7 +944,7 @@ void releaseallbuttons(void) } joyb = joyblast = 0; - for (i=0; i<256; i++) + for (i=0; i