MCPcopy Create free account
hub / github.com/DFHack/dfhack / screen_doSimulateInput

Function screen_doSimulateInput

library/LuaApi.cpp:3230–3265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3228}
3229
3230static int screen_doSimulateInput(lua_State *L)
3231{
3232 auto screen = Lua::CheckDFObject<df::viewscreen>(L, 1);
3233 luaL_checktype(L, 2, LUA_TTABLE);
3234
3235 if (!screen)
3236 luaL_argerror(L, 1, "NULL screen");
3237
3238 int sz = lua_rawlen(L, 2);
3239 std::set<df::interface_key> keys;
3240
3241 char str = '\0';
3242 for (int j = 1; j <= sz; j++)
3243 {
3244 lua_rawgeti(L, 2, j);
3245 df::interface_key k = (df::interface_key)lua_tointeger(L, -1);
3246 if (!str && k > df::interface_key::STRING_A000 && k <= df::interface_key::STRING_A255)
3247 str = Screen::keyToChar(k);
3248 keys.insert(k);
3249 lua_pop(L, 1);
3250 }
3251
3252 // if we're injecting a text keybinding, ensure it is reflected in the enabler text buffer
3253 string prev_input;
3254 if (str) {
3255 prev_input = (const char *)&df::global::enabler->last_text_input[0];
3256 df::global::enabler->last_text_input[0] = str;
3257 df::global::enabler->last_text_input[1] = '\0';
3258 }
3259
3260 screen->feed(&keys);
3261
3262 if (str)
3263 strcpy((char *)&df::global::enabler->last_text_input[0], prev_input.c_str());
3264 return 0;
3265}
3266
3267static int screen_keyToChar(lua_State *L)
3268{

Callers

nothing calls this directly

Calls 7

luaL_checktypeFunction · 0.85
luaL_argerrorFunction · 0.85
lua_rawlenFunction · 0.85
lua_rawgetiFunction · 0.85
c_strMethod · 0.80
insertMethod · 0.45
feedMethod · 0.45

Tested by

no test coverage detected