diff --git a/runtime/input.c b/runtime/input.c index 9508fe97..108b967b 100644 --- a/runtime/input.c +++ b/runtime/input.c @@ -555,15 +555,20 @@ void input_menu(int open) { ikb_cursor_update(); } -// 1 while flag (g_block, g_menu) blocks the game's input; state 2 ends at the first poll with nothing held. -static int blocked(volatile int32_t *flag, uint64_t buttons) { +// 1 while flag (g_block, g_menu) blocks the game's input; state 2 ends at the first poll with nothing held. A stick +// axis counts as held as well: with the walk key the keyboard's sticks move part way without setting a direction bit, so +// a gate that watched the buttons alone would let that movement through the moment the menu or the text entry closes. +static int blocked(volatile int32_t *flag, uint64_t buttons, const int32_t *axes) { int32_t k = *flag; - return k && !(k == 2 && !buttons && plat_cas32(flag, 0, 2) == 2); + int held = buttons != 0; + for (int i = 0; i < 4; i++) held |= axes[i] != 0; + return k && !(k == 2 && !held && plat_cas32(flag, 0, 2) == 2); } void input_poll(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx, int32_t *ry) { poll_merged(buttons, lx, ly, rx, ry); - int text = blocked(&g_block, *buttons), menu = blocked(&g_menu, *buttons); + const int32_t axes[4] = {*lx, *ly, *rx, *ry}; + int text = blocked(&g_block, *buttons, axes), menu = blocked(&g_menu, *buttons, axes); if (!text && !menu) return; *buttons = 0; *lx = *ly = *rx = *ry = 0; } diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index cbe200e3..8617b158 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -669,11 +669,13 @@ static const char *pad_layout_note(void) { } // The action a key presses, or -1: the walk key is a key of its own, but Shift is B in the default bindings, and a -// walk key that also presses something walks and does that something at the same time. -static int key_action(int key) { +// walk key that also presses something walks and does that something at the same time. The bindings come from a +// snapshot, and every key of an action is looked at: binds_refresh rebuilds the live table on the polling thread while +// the menu draws, and an action may hold more than the two keys its cells show. +static int key_action(const InputMap *m, int key) { for (int a = 0; a < ACTION_COUNT; a++) { - uint8_t keys[2]; - int n = input_map_keys_of(&input_map, a, keys, 2); + uint8_t keys[INPUT_BINDING_MAX]; + int n = input_map_keys_of(m, a, keys, INPUT_BINDING_MAX); for (int i = 0; i < n; i++) if (keys[i] == key) return a; } @@ -690,9 +692,11 @@ static void row_walk_key(void) { const char *cur = cfg_value("TOTK_WALK_KEY"); static char note[64]; const char *n = nullptr; + InputMap m; + input_map_snapshot(&m); for (int k = KEY_A; k < KEY_COUNT && !n; k++) { if (!input_key_name(k) || _stricmp(input_key_name(k), cur)) continue; - int a = key_action(k); + int a = key_action(&m, k); if (a >= 0 && input_action_name(a)) snprintf(note, sizeof note, menu_text(UI_MENU_WALK_KEY_TAKEN), input_action_name(a)), n = note; } opt_choice_list("TOTK_WALK_KEY", UI_MENU_WALK_KEY, keys, names, sizeof keys / sizeof *keys, UI_MENU_WALK_KEY_DESC,