mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +02:00
Make isDown accept a list of keys (issue #121)
This commit is contained in:
@@ -31,14 +31,15 @@ namespace sdl
|
|||||||
return "love.keyboard.sdl";
|
return "love.keyboard.sdl";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Keyboard::isDown(Key key) const
|
bool Keyboard::isDown(Key * keylist) const
|
||||||
{
|
{
|
||||||
SDLKey k;
|
SDLKey k;
|
||||||
|
Uint8 * keystate = SDL_GetKeyState(0);
|
||||||
|
|
||||||
if(keys.find(key, k))
|
for (Key key = *keylist; key != KEY_MAX_ENUM; key = *(++keylist))
|
||||||
{
|
{
|
||||||
Uint8 * keystate = SDL_GetKeyState(0);
|
if (keys.find(key, k) && keystate[(unsigned)k] == 1)
|
||||||
return keystate[(unsigned)k] == 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace sdl
|
|||||||
* @param key A key identifier.
|
* @param key A key identifier.
|
||||||
* @return boolean
|
* @return boolean
|
||||||
**/
|
**/
|
||||||
bool isDown(Key key) const;
|
bool isDown(Key * keylist) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables key repeating.
|
* Enables key repeating.
|
||||||
|
|||||||
@@ -31,16 +31,18 @@ namespace sdl
|
|||||||
int w_isDown(lua_State * L)
|
int w_isDown(lua_State * L)
|
||||||
{
|
{
|
||||||
Keyboard::Key k;
|
Keyboard::Key k;
|
||||||
|
unsigned int num = lua_gettop(L);
|
||||||
|
Keyboard::Key * keylist = new Keyboard::Key[num+1];
|
||||||
|
unsigned int counter = 0;
|
||||||
|
|
||||||
if(Keyboard::getConstant(luaL_checkstring(L, 1), k))
|
for (unsigned int i = 0; i < num; i++)
|
||||||
{
|
{
|
||||||
luax_pushboolean(L, instance->isDown(k));
|
if(Keyboard::getConstant(luaL_checkstring(L, i+1), k))
|
||||||
}
|
keylist[counter++] = k;
|
||||||
else
|
|
||||||
{
|
|
||||||
luax_pushboolean(L, false);
|
|
||||||
}
|
}
|
||||||
|
keylist[counter] = Keyboard::KEY_MAX_ENUM;
|
||||||
|
|
||||||
|
luax_pushboolean(L, instance->isDown(keylist));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user