From 1226f3ec502ccf290405ac05bcb741b5c4a57769 Mon Sep 17 00:00:00 2001 From: Nathan Fulton Date: Mon, 5 Sep 2016 13:01:09 -0400 Subject: [PATCH] Implement SDL HostGetCurrentKeyState() --- game/sdl/host.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/game/sdl/host.cpp b/game/sdl/host.cpp index 8def587..4dfbe13 100644 --- a/game/sdl/host.cpp +++ b/game/sdl/host.cpp @@ -626,7 +626,26 @@ long HostRunSpeedTests(DibBitmap *pbmSrc) dword HostGetCurrentKeyState(dword keyBit) { - return 0; + struct KeyBitVKey { + dword keyBit; + short vk; + } s_akk[] = { + {keyBitPageUp, SDL_SCANCODE_UP}, + {keyBitPageDown, SDL_SCANCODE_DOWN}, + {keyBitDpadLeft, SDL_SCANCODE_LEFT}, + {keyBitDpadRight, SDL_SCANCODE_RIGHT}, + {keyBitDpadButton, SDL_SCANCODE_RETURN}, + }; + Assert(keyBit != 0); + + dword keyBitRet = 0; + const Uint8 *state = SDL_GetKeyboardState(NULL); + for (int i = 0; i < sizeof(s_akk) / sizeof(KeyBitVKey); i++) + if ((keyBit & s_akk[i].keyBit) != 0) + if (state[s_akk[i].vk]) + keyBitRet |= s_akk[i].keyBit; + + return keyBitRet; } bool HostIsPenDown()