You're getting an error because you're currently processing all input, including mouse events (InputEventMouse
), which doesn't have the scancode
property.
You just need to use an if-statement to make sure it's a key press/release.
func _input(event):
if !event.is_echo(): # ignore when key held down
if event is InputEventKey:
if event.is_pressed():
var key_press: InputEventKey = event
match key_press.scancode:
KEY_J:
print("Pressed J Key")
else: # released
var key_release: InputEventKey = event
match key_release.scancode:
KEY_J:
print("Released J Key")