diff --git a/library/include/modules/Screen.h b/library/include/modules/Screen.h index 887fb5f75..daa08ca59 100644 --- a/library/include/modules/Screen.h +++ b/library/include/modules/Screen.h @@ -229,6 +229,9 @@ namespace DFHack DFHACK_EXPORT bool hasActiveScreens(Plugin *p); DFHACK_EXPORT void raise(df::viewscreen *screen); + // returns a new set with text interface keys from the text buffer added in (if any) + DFHACK_EXPORT std::set add_text_keys(const std::set& keys); + /// Retrieve the string representation of the bound key. DFHACK_EXPORT std::string getKeyDisplay(df::interface_key key); diff --git a/library/modules/Screen.cpp b/library/modules/Screen.cpp index a36f387b6..d3419398c 100644 --- a/library/modules/Screen.cpp +++ b/library/modules/Screen.cpp @@ -78,7 +78,6 @@ namespace DFHack { DBG_DECLARE(core, screen, DebugCategory::LINFO); } - /* * Screen painting API. */ @@ -586,6 +585,17 @@ void Hide::merge() { } } } +std::set Screen::add_text_keys(const std::set& keys) { + std::set combined_keys(keys); + if (df::global::enabler->last_text_input[0]) { + char c = df::global::enabler->last_text_input[0]; + df::interface_key key = charToKey(c); + DEBUG(screen).print("adding character %c as interface key %ld\n", c, key); + combined_keys.emplace(key); + } + return combined_keys; +} + string Screen::getKeyDisplay(df::interface_key key) { if (enabler) @@ -940,7 +950,7 @@ int dfhack_lua_viewscreen::do_input(lua_State *L) } lua_pushvalue(L, -2); - Lua::PushInterfaceKeys(L, *keys); + Lua::PushInterfaceKeys(L, Screen::add_text_keys(*keys)); lua_call(L, 2, 0); self->update_focus(L, -1); @@ -1023,6 +1033,7 @@ void dfhack_lua_viewscreen::feed(std::set *keys) lua_pushlightuserdata(Lua::Core::State, keys); safe_call_lua(do_input, 1, 0); + df::global::enabler->last_text_input[0] = '\0'; } void dfhack_lua_viewscreen::onShow() diff --git a/plugins/overlay.cpp b/plugins/overlay.cpp index 784e17129..7185f73a1 100644 --- a/plugins/overlay.cpp +++ b/plugins/overlay.cpp @@ -76,7 +76,7 @@ struct viewscreen_overlay : T { [&](lua_State *L) { Lua::Push(L, T::_identity.getName()); Lua::Push(L, this); - Lua::PushInterfaceKeys(L, *input); + Lua::PushInterfaceKeys(L, Screen::add_text_keys(*input)); }, [&](lua_State *L) { input_is_handled = lua_toboolean(L, -1); });