From 620748480b07df8f30435ec518a788dd9e50bc68 Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Thu, 2 Dec 2021 22:02:42 +0000 Subject: [PATCH] Merge branch 'lua_missing_key_codes' into 'master' Lua binding for SDL_GetKeyName, two missing scan codes See merge request OpenMW/openmw!1450 (cherry picked from commit d86e7d4c9a28bc96af0a5638b26879fa49b8a847) 9a073baa Add Apostrophe and Period scan codes d66f3a35 Add getKeyName to Lua input API ed64add9 Replace mentions of KeyEvent with KEY --- apps/openmw/mwlua/inputbindings.cpp | 6 ++++++ files/lua_api/openmw/input.lua | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwlua/inputbindings.cpp b/apps/openmw/mwlua/inputbindings.cpp index 6707d35d3b..8aecd1269c 100644 --- a/apps/openmw/mwlua/inputbindings.cpp +++ b/apps/openmw/mwlua/inputbindings.cpp @@ -71,6 +71,10 @@ namespace MWLua api["getControlSwitch"] = [input](std::string_view key) { return input->getControlSwitch(key); }; api["setControlSwitch"] = [input](std::string_view key, bool v) { input->toggleControlSwitch(key, v); }; + api["getKeyName"] = [](SDL_Scancode code) { + return SDL_GetKeyName(SDL_GetKeyFromScancode(code)); + }; + api["ACTION"] = LuaUtil::makeReadOnly(context.mLua->tableFromPairs({ {"GameMenu", MWInput::A_GameMenu}, {"Screenshot", MWInput::A_Screenshot}, @@ -252,6 +256,7 @@ namespace MWLua {"RightBracket", SDL_SCANCODE_RIGHTBRACKET}, {"RightShift", SDL_SCANCODE_RSHIFT}, + {"Apostrophe", SDL_SCANCODE_APOSTROPHE}, {"BackSlash", SDL_SCANCODE_BACKSLASH}, {"Backspace", SDL_SCANCODE_BACKSPACE}, {"CapsLock", SDL_SCANCODE_CAPSLOCK}, @@ -267,6 +272,7 @@ namespace MWLua {"NumLock", SDL_SCANCODE_NUMLOCKCLEAR}, {"PageDown", SDL_SCANCODE_PAGEDOWN}, {"PageUp", SDL_SCANCODE_PAGEUP}, + {"Period", SDL_SCANCODE_PERIOD}, {"Pause", SDL_SCANCODE_PAUSE}, {"PrintScreen", SDL_SCANCODE_PRINTSCREEN}, {"ScrollLock", SDL_SCANCODE_SCROLLLOCK}, diff --git a/files/lua_api/openmw/input.lua b/files/lua_api/openmw/input.lua index d4ff7f3475..361073e79d 100644 --- a/files/lua_api/openmw/input.lua +++ b/files/lua_api/openmw/input.lua @@ -20,7 +20,7 @@ ------------------------------------------------------------------------------- -- Is a keyboard button currently pressed. -- @function [parent=#input] isKeyPressed --- @param #number keyCode Key code (the same code that is used in @{openmw.input#KeyEvent}) +-- @param #number keyCode Key code (see @{openmw.input#KEY}) -- @return #boolean ------------------------------------------------------------------------------- @@ -83,6 +83,12 @@ -- @param #string key Control type (see @{openmw.input#CONTROL_SWITCH}) -- @param #boolean value +------------------------------------------------------------------------------- +-- Returns a human readable name for the given key code +-- @function [parent=#input] getKeyName +-- @param #number code A key code (see @{openmw.input#KEY}) +-- @return #string + ------------------------------------------------------------------------------- -- @type CONTROL_SWITCH -- @field [parent=#CONTROL_SWITCH] #string Controls Ability to move @@ -268,6 +274,7 @@ -- @field #number RightBracket -- @field #number RightSuper -- @field #number RightShift +-- @field #number Apostrophe -- @field #number BackSlash -- @field #number Backspace -- @field #number CapsLock @@ -284,6 +291,7 @@ -- @field #number PageDown -- @field #number PageUp -- @field #number Pause +-- @field #number Period -- @field #number PrintScreen -- @field #number ScrollLock -- @field #number Semicolon