Merge pull request #3665 from myk002/myk_keykey

Refine keyboard input handing
develop
Myk 2023-08-11 18:22:35 -07:00 committed by GitHub
commit 1307c727cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 4 deletions

@ -38,7 +38,7 @@ keybinding add Ctrl-V@dwarfmode digv
keybinding add Ctrl-Shift-V@dwarfmode "digv x" keybinding add Ctrl-Shift-V@dwarfmode "digv x"
# clean the selected tile of blood etc # clean the selected tile of blood etc
keybinding add Ctrl-C spotclean keybinding add Ctrl-C@dwarfmode spotclean
# destroy the selected item # destroy the selected item
keybinding add Ctrl-K@dwarfmode autodump-destroy-item keybinding add Ctrl-K@dwarfmode autodump-destroy-item

@ -59,6 +59,7 @@ Template for new versions:
## Fixes ## Fixes
- Core: properly reload scripts in mods when a world is unloaded and immediately loaded again - Core: properly reload scripts in mods when a world is unloaded and immediately loaded again
- Core: fix text getting added to DFHack text entry widgets when Alt- or Ctrl- keys are hit
## Misc Improvements ## Misc Improvements
- Surround DFHack-specific UI elements with square brackets instead of red-yellow blocks for better readability - Surround DFHack-specific UI elements with square brackets instead of red-yellow blocks for better readability

@ -2400,9 +2400,13 @@ bool Core::DFH_SDL_Event(SDL_Event* ev)
DEBUG(keybinding).print("key down: sym=%d (%c)\n", sym, sym); DEBUG(keybinding).print("key down: sym=%d (%c)\n", sym, sym);
bool handled = SelectHotkey(sym, modstate); bool handled = SelectHotkey(sym, modstate);
if (handled) { if (handled) {
hotkey_states[sym] = true;
if (modstate & (DFH_MOD_CTRL | DFH_MOD_ALT)) {
DEBUG(keybinding).print("modifier key detected; not inhibiting SDL key down event\n");
return false;
}
DEBUG(keybinding).print("%sinhibiting SDL key down event\n", DEBUG(keybinding).print("%sinhibiting SDL key down event\n",
suppress_duplicate_keyboard_events ? "" : "not "); suppress_duplicate_keyboard_events ? "" : "not ");
hotkey_states[sym] = true;
return suppress_duplicate_keyboard_events; return suppress_duplicate_keyboard_events;
} }
} }
@ -2414,7 +2418,11 @@ bool Core::DFH_SDL_Event(SDL_Event* ev)
} }
else if (ev->type == SDL_TEXTINPUT) { else if (ev->type == SDL_TEXTINPUT) {
auto &te = ev->text; auto &te = ev->text;
DEBUG(keybinding).print("text input: '%s'\n", te.text); DEBUG(keybinding).print("text input: '%s' (modifiers: %s%s%s)\n",
te.text,
modstate & DFH_MOD_SHIFT ? "Shift" : "",
modstate & DFH_MOD_CTRL ? "Ctrl" : "",
modstate & DFH_MOD_ALT ? "Alt" : "");
if (strlen(te.text) == 1 && hotkey_states[te.text[0]]) { if (strlen(te.text) == 1 && hotkey_states[te.text[0]]) {
DEBUG(keybinding).print("%sinhibiting SDL text event\n", DEBUG(keybinding).print("%sinhibiting SDL text event\n",
suppress_duplicate_keyboard_events ? "" : "not "); suppress_duplicate_keyboard_events ? "" : "not ");

@ -589,7 +589,7 @@ std::set<df::interface_key> Screen::normalize_text_keys(const std::set<df::inter
std::set<df::interface_key> combined_keys; std::set<df::interface_key> combined_keys;
std::copy_if(keys.begin(), keys.end(), std::inserter(combined_keys, combined_keys.begin()), std::copy_if(keys.begin(), keys.end(), std::inserter(combined_keys, combined_keys.begin()),
[](df::interface_key k){ return k <= df::interface_key::STRING_A000 || k > df::interface_key::STRING_A255; } ); [](df::interface_key k){ return k <= df::interface_key::STRING_A000 || k > df::interface_key::STRING_A255; } );
if (df::global::enabler->last_text_input[0]) { if (!(Core::getInstance().getModstate() & (DFH_MOD_CTRL | DFH_MOD_ALT)) && df::global::enabler->last_text_input[0]) {
char c = df::global::enabler->last_text_input[0]; char c = df::global::enabler->last_text_input[0];
df::interface_key key = charToKey(c); df::interface_key key = charToKey(c);
DEBUG(screen).print("adding character %c as interface key %ld\n", c, key); DEBUG(screen).print("adding character %c as interface key %ld\n", c, key);