Hello!
Could someone help me understand why my input event isn’t a match?
I’m trying to separate keyboard inputs from controller inputs and the documents made it seem like .is_match() would be the best way to match input events types but I guess not? I’m getting false returned for key events that should match. Thank you for any help! Please let me know if more information is needed!
#finds if the action is a keyboard or not and passes back the correct input
print(action)
for events in action:
print(str(events))
print(str(events.is_match(InputEventKey)))
if isItKeyboard == true and events.is_match(InputEventKey) == true:
return str(action[events]).capitalize()
return "error"
Would you mind explaining why you need to separate the keyboard from gamepad input?
I’m curious, because usually you shouldn’t need to do that, unless there is a very specific case you need to solve.
If you really need to, then the easiest way would be to use separate InputEventAction for keyboard and gamepad in the ProjectSettings and use these to differentiate inputs.
In your code snippet, you’re using the is_match() method wrong, you’re passing InputEventKey, which is just a class, but this method expects an InputEvent object.
But I wouldn’t do it this way anyway, but rather try to make it work with actions as mentioned in the previous paragraph.
I’m trying to make a keybind/ rebind keys GUI! If you have any other advice for making one I would love it! I don’t think I’m going to go with separate InputEventAction as in the long run I fear that may complicate and confuse me going forward with the project. I am curious though, what would should i be using to find a match for the class instead? Thank you so much!
If you want to know if the event is an InputEventKey or an InputEventJoypadButton then you can use the is keyword:
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventKey:
# event is a keyboard key
pass
elif event is InputEventJoypadButton:
# event is a gamepad button
pass