diff --git a/builtin/common/settings/dlg_change_keybinding.lua b/builtin/common/settings/dlg_change_keybinding.lua index 99c453223..6c317ba5d 100644 --- a/builtin/common/settings/dlg_change_keybinding.lua +++ b/builtin/common/settings/dlg_change_keybinding.lua @@ -24,7 +24,7 @@ local function get_formspec(dialogdata) local cells = {} for _, key in ipairs(value) do - table.insert(cells, core.formspec_escape(key)) + table.insert(cells, core.formspec_escape(core.get_keycode_name(key))) end table.insert(fs, ("textlist[0.5,1.3;5,4;keylist;%s;%d;false]"):format(table.concat(cells, ","), selection)) diff --git a/src/script/lua_api/l_menu_common.cpp b/src/script/lua_api/l_menu_common.cpp index 428b902c9..3a512fcd3 100644 --- a/src/script/lua_api/l_menu_common.cpp +++ b/src/script/lua_api/l_menu_common.cpp @@ -42,6 +42,14 @@ int ModApiMenuCommon::l_normalize_keycode(lua_State *L) return 1; } +int ModApiMenuCommon::l_get_keycode_name(lua_State *L) +{ + auto keystr = luaL_checkstring(L, 1); + auto name = KeyPress(keystr).name(); + lua_pushstring(L, name.empty() ? "" : gettext(name.c_str())); + return 1; +} + void ModApiMenuCommon::Initialize(lua_State *L, int top) { @@ -49,6 +57,7 @@ void ModApiMenuCommon::Initialize(lua_State *L, int top) API_FCT(get_active_driver); API_FCT(irrlicht_device_supports_touch); API_FCT(normalize_keycode); + API_FCT(get_keycode_name); } diff --git a/src/script/lua_api/l_menu_common.h b/src/script/lua_api/l_menu_common.h index 2c1756fa5..b0ea9cb5e 100644 --- a/src/script/lua_api/l_menu_common.h +++ b/src/script/lua_api/l_menu_common.h @@ -14,6 +14,7 @@ private: static int l_get_active_driver(lua_State *L); static int l_irrlicht_device_supports_touch(lua_State *L); static int l_normalize_keycode(lua_State *L); + static int l_get_keycode_name(lua_State *L); public: static void Initialize(lua_State *L, int top);