2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010 - Côme <MCMic> BERNIGAUD
5 This file is part of Lugaru.
7 Lugaru is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 See the GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 /**> HEADER FILES <**/
26 extern bool keyboardfrozen;
28 bool keyDown[SDLK_LAST + 6];
29 bool keyPressed[SDLK_LAST + 6];
34 Uint8 *keyState = SDL_GetKeyState(NULL);
35 for (int i = 0; i < SDLK_LAST; i++) {
36 keyPressed[i] = !keyDown[i] && keyState[i];
37 keyDown[i] = keyState[i];
39 Uint8 mb = SDL_GetMouseState(NULL, NULL);
40 for (int i = 1; i < 6; i++) {
41 keyPressed[SDLK_LAST + i] = !keyDown[SDLK_LAST + i] && (mb & SDL_BUTTON(i));
42 keyDown[SDLK_LAST + i] = (mb & SDL_BUTTON(i));
46 bool Input::isKeyDown(int k)
48 if (keyboardfrozen || k >= SDLK_LAST + 6) // really useful? check that.
53 bool Input::isKeyPressed(int k)
55 if (keyboardfrozen || k >= SDLK_LAST + 6)
60 const char* Input::keyToChar(unsigned short i)
63 return SDL_GetKeyName(SDLKey(i));
64 else if (i == SDLK_LAST + SDL_BUTTON_LEFT)
66 else if (i == SDLK_LAST + SDL_BUTTON_RIGHT)
68 else if (i == SDLK_LAST + SDL_BUTTON_MIDDLE)
74 unsigned short Input::CharToKey(const char* which)
76 for (unsigned short i = 0; i < SDLK_LAST; i++) {
77 if (!strcasecmp(which, SDL_GetKeyName(SDLKey(i))))
80 if (!strcasecmp(which, "mouse1")) {
83 if (!strcasecmp(which, "mouse2")) {
89 Boolean Input::MouseClicked()
91 return isKeyPressed(SDLK_LAST + SDL_BUTTON_LEFT);