why this gives me an error?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lalel345

why this gives me an error?

func _input(event):
	var keys = event as InputEventKey
	if keys.scancode == KEY_J:
		print(keys)
:bust_in_silhouette: 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")