Improve Shortcut.matches_event() not matching InputEventKey events precisely #10758
Jowan-Spooner
started this conversation in
GUI
Replies: 1 comment 3 replies
-
There's a simple workaround for this, allowing you to do any variation on what you want matched: func my_check(list_event: InputEvent, check_event: InputEvent, exact: bool, check_pressed: bool, check_echo: bool) -> bool:
return list_event and list_event.is_match(check_event, exact) and (not check_pressed or list_event.is_pressed() == check_event.is_pressed()) and (not check_echo or list_event.is_echo() == check_event.is_echo())
func _input(event: InputEvent) -> void:
if shortcut.events.any(my_check.bind(event, true, true, true)):
do_something() For example, or just configure as you wish For comparison, this is the code of the actual check: bool Shortcut::matches_event(const Ref<InputEvent> &p_event) const {
Ref<InputEventShortcut> ies = p_event;
if (ies.is_valid()) {
if (ies->get_shortcut().ptr() == this) {
return true;
}
}
for (int i = 0; i < events.size(); i++) {
Ref<InputEvent> ie = events[i];
bool valid = ie.is_valid() && ie->is_match(p_event);
// Stop on first valid event - don't need to check further.
if (valid) {
return true;
}
}
return false;
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
As explained in godotengine/godot#97048
Shortcut.matches_event()
a Shortcut setup with an InputEventKey event currently ignores theInputEventKey.pressed
property and will always returntrue
for both pressed and released variants of that event. This is easy to workaround, but unintuitive.Intuitively I setup a shortcut like this:

Then checked for the shortcut like this:
However this will trigger twice for any InputEventKey which is not what you want for a shortcut and feels unintuitive because you can change the
pressed
property of the InputEventKey but that has no effect unless you check it manually like this:Apparently this is intended (not sure what for) and standard (InputEvent.matches()) does this too. I don't know of the use cases of InputEvent.matches() but at least for shortcuts this feels strange.
Interestingly the same is true for
InputEventKey.echo
. Also something uncommon for shortcuts and something you have to check manually.Maybe the most intuitive solution would be to hide
pressed
,echo
and similar "event state" properties from the inspector cause editing/seeing them is probably what confused me. However I assume this is not a good solution either.Not sure how to best solve this, but the current workflow is confusing.
Beta Was this translation helpful? Give feedback.
All reactions