Changed the love.keypressed and love.keyreleased event callbacks to be love.keypressed(key, scancode, isrepeat) and love.keyreleased(key, scancode). Added love.keyboard.isScancodeDown. Resolves issue #993.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2015-02-16 17:10:03 -04:00
parent cce995146f
commit 5c1e6014cc
6 changed files with 98 additions and 24 deletions
+31 -4
View File
@@ -47,14 +47,31 @@ bool Keyboard::hasKeyRepeat() const
return key_repeat;
}
bool Keyboard::isDown(Key *keylist) const
bool Keyboard::isDown(const std::vector<Key> &keylist) const
{
const Uint8 *keystate = SDL_GetKeyboardState(nullptr);
const Uint8 *state = SDL_GetKeyboardState(nullptr);
for (Key key = *keylist; key != KEY_MAX_ENUM; key = *(++keylist))
for (Key key : keylist)
{
SDL_Scancode scancode = SDL_GetScancodeFromKey(keymap[key]);
if (keystate[scancode])
if (state[scancode])
return true;
}
return false;
}
bool Keyboard::isScancodeDown(const std::vector<Scancode> &scancodelist) const
{
const Uint8 *state = SDL_GetKeyboardState(nullptr);
for (Scancode scancode : scancodelist)
{
SDL_Scancode sdlscancode = SDL_SCANCODE_UNKNOWN;
if (!scancodes.find(scancode, sdlscancode))
continue;
if (state[sdlscancode])
return true;
}
@@ -105,6 +122,16 @@ bool Keyboard::hasTextInput() const
return SDL_IsTextInputActive();
}
bool Keyboard::getConstant(Scancode in, SDL_Scancode &out)
{
return scancodes.find(in, out);
}
bool Keyboard::getConstant(SDL_Scancode in, Scancode &out)
{
return scancodes.find(in, out);
}
const SDL_Keycode *Keyboard::createKeyMap()
{
// Array must be static so its lifetime continues once the function returns.