event.pressed & event.scancode

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

Hello, I’m still a beginner with Godot and GDScript. This is not a very important question and it might be a dumb one but I’m just asking it to better understand what’s happening.

Ok, so when I execute the following code it will obviously print “KEY_UP” every time I press the up arrow key:

func _unhandled_key_input(event):
	if event is InputEventKey:
		if event.pressed and event.scancode == KEY_UP:

Now when I omit the “event.pressed” it will do basically the same but now it will print the “KEY_UP” twice every time the up arrow key is pressed:

func _unhandled_key_input(event):
	if event is InputEventKey:
		if event.scancode == KEY_UP:

Why is it now printing it twice?

:bust_in_silhouette: Reply From: ramazan

I think.
Here “if event.pressed and event.scancode == KEY_UP:” only refers to “pressed” (ie “key down”).

But here “if event.scancode == KEY_UP:” . “press and release” .
So : pressed = print(“bla bla”)
release = print(“bla bla”)