/** * \brief Determines from the savegame the low-level keyboard key where the * specified game command is mapped. * \param command A game command. * \return The keyboard key mapped to this game command in the savegame. */ InputEvent::KeyboardKey GameCommands::get_saved_keyboard_binding( GameCommand command) const { const std::string& savegame_variable = get_keyboard_binding_savegame_variable(command); const std::string& keyboard_key_name = get_savegame().get_string(savegame_variable); return name_to_enum(keyboard_key_name, InputEvent::KEY_NONE); }
/** * \brief Implementation of sol.input.is_key_pressed(). * \param l The Lua context that is calling this function. * \return Number of values to return to Lua. */ int LuaContext::input_api_is_key_pressed(lua_State* l) { return LuaTools::exception_boundary_handle(l, [&] { const std::string& key_name = LuaTools::check_string(l, 1); InputEvent::KeyboardKey key = name_to_enum(key_name, InputEvent::KEY_NONE); if (key == InputEvent::KEY_NONE) { LuaTools::arg_error(l, 1, std::string( "Unknown keyboard key name: '") + key_name + "'"); } lua_pushboolean(l, InputEvent::is_key_down(key)); return 1; }); }
/** * \brief Implementation of sol.input.is_mouse_button_released(). * \param l The Lua context that is calling this function. * \return Number of values to return to Lua. */ int LuaContext::input_api_is_mouse_button_released(lua_State* l) { return LuaTools::exception_boundary_handle(l, [&] { const std::string& button_name = LuaTools::check_string(l, 1); InputEvent::MouseButton button = name_to_enum(button_name, InputEvent::MOUSE_BUTTON_NONE); if (button == InputEvent::MOUSE_BUTTON_NONE) { LuaTools::arg_error(l, 1, std::string( "Unknown mouse button name: '") + button_name + "'"); } lua_pushboolean(l, !InputEvent::is_mouse_button_down(button)); return 1; }); }