X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FInput.cpp;h=88970f90bbb32cf2c37a371bf341e9e0a8c8d2a8;hb=1c7d28a2fc93699ab955ea66203d0c36bba9d977;hp=059879037f7095022339cb086ef16d0af949d0dc;hpb=eaca5a12f009c9fb9c95a2e728a071e972e698d0;p=lugaru.git diff --git a/Source/Input.cpp b/Source/Input.cpp index 0598790..88970f9 100644 --- a/Source/Input.cpp +++ b/Source/Input.cpp @@ -25,47 +25,48 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern bool keyboardfrozen; -bool keyDown[SDLK_LAST + 6]; -bool keyPressed[SDLK_LAST + 6]; +bool keyDown[SDL_NUM_SCANCODES + 6]; +bool keyPressed[SDL_NUM_SCANCODES + 6]; void Input::Tick() { SDL_PumpEvents(); - Uint8 *keyState = SDL_GetKeyState(NULL); - for (int i = 0; i < SDLK_LAST; i++) { + int numkeys; + const Uint8 *keyState = SDL_GetKeyboardState(&numkeys); + for (int i = 0; i < numkeys; i++) { keyPressed[i] = !keyDown[i] && keyState[i]; keyDown[i] = keyState[i]; } Uint8 mb = SDL_GetMouseState(NULL, NULL); for (int i = 1; i < 6; i++) { - keyPressed[SDLK_LAST + i] = !keyDown[SDLK_LAST + i] && (mb & SDL_BUTTON(i)); - keyDown[SDLK_LAST + i] = (mb & SDL_BUTTON(i)); + keyPressed[SDL_NUM_SCANCODES + i] = !keyDown[SDL_NUM_SCANCODES + i] && (mb & SDL_BUTTON(i)); + keyDown[SDL_NUM_SCANCODES + i] = (mb & SDL_BUTTON(i)); } } bool Input::isKeyDown(int k) { - if (keyboardfrozen || k >= SDLK_LAST + 6) // really useful? check that. + if (keyboardfrozen || k >= SDL_NUM_SCANCODES + 6) // really useful? check that. return false; return keyDown[k]; } bool Input::isKeyPressed(int k) { - if (keyboardfrozen || k >= SDLK_LAST + 6) + if (keyboardfrozen || k >= SDL_NUM_SCANCODES + 6) return false; return keyPressed[k]; } const char* Input::keyToChar(unsigned short i) { - if (i < SDLK_LAST) - return SDL_GetKeyName(SDLKey(i)); - else if (i == SDLK_LAST + SDL_BUTTON_LEFT) + if (i < SDL_NUM_SCANCODES) + return SDL_GetScancodeName(SDL_Scancode(i)); + else if (i == MOUSEBUTTON1) return "mouse1"; - else if (i == SDLK_LAST + SDL_BUTTON_RIGHT) + else if (i == MOUSEBUTTON2) return "mouse2"; - else if (i == SDLK_LAST + SDL_BUTTON_MIDDLE) + else if (i == MOUSEBUTTON3) return "mouse3"; else return "unknown"; @@ -73,8 +74,8 @@ const char* Input::keyToChar(unsigned short i) unsigned short Input::CharToKey(const char* which) { - for (unsigned short i = 0; i < SDLK_LAST; i++) { - if (!strcasecmp(which, SDL_GetKeyName(SDLKey(i)))) + for (unsigned short i = 0; i < SDL_NUM_SCANCODES; i++) { + if (!strcasecmp(which, SDL_GetScancodeName(SDL_Scancode(i)))) return i; } if (!strcasecmp(which, "mouse1")) { @@ -83,10 +84,13 @@ unsigned short Input::CharToKey(const char* which) if (!strcasecmp(which, "mouse2")) { return MOUSEBUTTON2; } - return SDLK_LAST; + if (!strcasecmp(which, "mouse3")) { + return MOUSEBUTTON3; + } + return SDL_NUM_SCANCODES; } Boolean Input::MouseClicked() { - return isKeyPressed(SDLK_LAST + SDL_BUTTON_LEFT); + return isKeyPressed(SDL_NUM_SCANCODES + SDL_BUTTON_LEFT); }