From daefc91a72c08ddd33302ca6a8433bf17ff32833 Mon Sep 17 00:00:00 2001 From: im-tem Date: Tue, 1 Jul 2025 17:45:04 +0300 Subject: [PATCH] input: hacky way of handling multikey shortcuts --- src/input.cpp | 14 +++++++++++--- src/input.h | 6 +++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index e61a1b9..906143b 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -109,9 +109,17 @@ input_held(Input* self, InputType type) bool input_release(Input* self, InputType type) { - for (KeyType key : INPUT_KEYS[type]) - if (!key_release(&self->keyboard, (key))) - return false; + for (size_t i = 0; i < INPUT_KEYS[type].size(); i++) { + auto& key = INPUT_KEYS[type][i]; + //below is some hackery to ensure that multikey shortcuts work... + //ideally would split this into a separate function or rename this? + if (i != INPUT_KEYS[type].size()) { + if (!key_held(&self->keyboard, key)) return false; + } + // last key in the shortcut chain, so in a mod1-mod2-...-key it won't be a mod key + // todo: introduce a list of modifer keys as a more reliable solution + else if (!key_release(&self->keyboard, (key))) return false; + }; return true; } diff --git a/src/input.h b/src/input.h index ef55b90..6107424 100644 --- a/src/input.h +++ b/src/input.h @@ -273,13 +273,13 @@ const std::vector INPUT_KEYS[INPUT_COUNT] = { KEY_2 }, { KEY_Z }, { KEY_Y }, - { KEY_LCTRL } + { KEY_LCTRL , KEY_S} }; struct Keyboard { - bool current[KEY_COUNT]; - bool previous[KEY_COUNT]; + bool current[KEY_COUNT] = { 0 }; + bool previous[KEY_COUNT] = { 0 }; }; struct Mouse