Topic was automatically imported from the old Question2Answer platform.
Asked By
Fati98
So i was watching a tutorial about some functions about keyboard and set_process_unhandled_input.But at the code i wrote there are two problems:
1-When i click right mouse button i get a error “invalid get index ‘x’ (on base:‘InputEventMouseButton’).”
2-This code supposed to warn me when i press anythnig besides right and left keys.But it still warns me when i press right and left keys.
For the first part, the error is essentially saying that the InputEventMouseButton class doesn’t have any property called x.
If you want to get the mouse position with the event, you should use event.position. position is a Vector2 and a property of the InputEventMouse class, which is the parent of InputEventMouseButton.
For the second part, remember that pressing and releasing a key or mouse button creates two separate events: One is for pressing the key, and the other is for releasing it. So even tho the press event of your right and left keys get consumed and handled in the _input, the release event will remain unhandled, and it’ll get passed to _unhandled_input.
So, what you’re getting is the warning related to the unhandled release event of right or left keys.
To fix it, in the _unhandled_input(), simply check if event is pressed. So:
func _unhandled_input(event: InputEvent) -> void:
if event.is_pressed():
print("Yasak tuş", event)
That’ll make sure that the warning is printed only when a key is being pressed, not when it’s being released.