Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | lalel345 |
why this gives me an error?
func _input(event):
var keys = event as InputEventKey
if keys.scancode == KEY_J:
print(keys)
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | lalel345 |
why this gives me an error?
func _input(event):
var keys = event as InputEventKey
if keys.scancode == KEY_J:
print(keys)
Reply From: | Error7Studios |
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")