mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user