diff --git a/src/g_input.c b/src/g_input.c index 87f4d5173..9b5b6d29a 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -89,26 +89,26 @@ static boolean CheckInputDown(UINT8 which, gamecontrols_e gc, boolean checkaxes) { INT32 (*controls)[2] = which == 0 ? gamecontrol : gamecontrolbis; - for (unsigned i = 0; i < 2; i++) + return G_CheckKeyDown(which, controls[gc][0], checkaxes) || G_CheckKeyDown(which, controls[gc][1], checkaxes); +} + +boolean G_CheckKeyDown(UINT8 which, INT32 key, boolean checkaxes) +{ + if (key >= KEY_GAMEPAD && key < KEY_AXES) { - INT32 key = controls[gc][i]; - - if (key >= KEY_GAMEPAD && key < KEY_AXES) - { - if (gamepads[which].buttons[key - KEY_GAMEPAD]) - return true; - } - else if (checkaxes && (key >= KEY_AXES && key < KEY_INV_AXES + NUM_GAMEPAD_AXES)) - { - const UINT16 jdeadzone = G_GetGamepadDigitalDeadZone(which); - const INT16 value = G_GetGamepadAxisValue(which, (key - KEY_AXES) % NUM_GAMEPAD_AXES); - - if (abs(value) > jdeadzone) - return true; - } - else if (gamekeydown[key]) + if (gamepads[which].buttons[key - KEY_GAMEPAD]) return true; } + else if (checkaxes && (key >= KEY_AXES && key < KEY_INV_AXES + NUM_GAMEPAD_AXES)) + { + const UINT16 jdeadzone = G_GetGamepadDigitalDeadZone(which); + const INT16 value = G_GetGamepadAxisValue(which, (key - KEY_AXES) % NUM_GAMEPAD_AXES); + + if (abs(value) > jdeadzone) + return true; + } + else if (gamekeydown[key]) + return true; return false; } diff --git a/src/g_input.h b/src/g_input.h index bb50d3516..84f3425e8 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -285,6 +285,7 @@ extern INT32 gamecontrolbis[NUM_GAMECONTROLS][2]; // secondary splitscreen playe extern INT32 gamecontroldefault[num_gamecontrolschemes][NUM_GAMECONTROLS][2]; extern INT32 gamecontrolbisdefault[num_gamecontrolschemes][NUM_GAMECONTROLS][2]; +boolean G_CheckKeyDown(UINT8 which, INT32 key, boolean checkaxes); boolean G_PlayerInputDown(UINT8 which, gamecontrols_e gc); boolean G_CheckDigitalPlayerInput(UINT8 which, gamecontrols_e gc); diff --git a/src/lua_inputlib.c b/src/lua_inputlib.c index e4962a0fb..83a6a714b 100644 --- a/src/lua_inputlib.c +++ b/src/lua_inputlib.c @@ -170,8 +170,8 @@ static int lib_getGameKeyDown(lua_State *L) { int i = luaL_checkinteger(L, 2); if (i < 0 || i >= NUMINPUTS) - return luaL_error(L, "gamekeydown[] index %d out of range (0 - %d)", i, NUMINPUTS-1); - lua_pushboolean(L, gamekeydown[i]); + return luaL_error(L, "Key index %d out of range (0 - %d)", i, NUMINPUTS-1); + lua_pushboolean(L, G_CheckKeyDown(0, i, false) || G_CheckKeyDown(1, i, false)); return 1; }