Buttons not accepting keyboard input properly

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rgrams
:warning: Old Version Published before Godot 3 was released.

I’m using TextureButtons and and they work fine with the mouse: press the mouse button, the TextureButton fires “pressed”; release the mouse button, the TextureButton fires “released”. But the keyboard “ui_accept” input doesn’t work right—it does nothing on key press and fires “pressed” when the key is released. Is this an engine bug, or is there an option I need to check?

Thanks!

:bust_in_silhouette: Reply From: volzhs

Button fires “pressed” event when release mouse button by default.
If you want “pressed” event when mouse button is pressed state,
Check “Click On Press” on Inspector of Button.

This is what reference says.

Set the button click_on_press mode. This mode generates click events when a mouse button or key is just pressed (by default events are generated when the button/keys are released and both press and release occur in the visual area of the Button).

Yep, I figured that out, I have “Click On Press” checked. The problem is keyboard input doesn’t behave the same way.

If that’s what the docs say, I guess it is a bug.

rgrams | 2016-06-24 15:31

:bust_in_silhouette: Reply From: ericdl

It’s working properly on my end with the texturebutton’s Click On Press property set to On.

func _input(event):
	if event.is_action_pressed("ui_accept"): _on_TextureButton_pressed()
	if event.is_action_released("ui_accept"): _on_TextureButton_released()

func _on_TextureButton_pressed():
	print("texturebutton pressed")

func _on_TextureButton_released():
	print("texturebutton released")

Yes, that works because you’re manually checking for the input actions.
If instead, you connect to the pressed and released signals, only pressed will fire on keyboard input.
So I can confirm it’s a bug (on 2.1-dev).

Hinsbart | 2016-06-24 21:42

Sorry, i don’t understand. He mentioned firing the “ui_accept” action in a TextureButton via keypress, how can we do that via signal?

ericdl | 2016-06-24 22:32

Like this.
Of course you may use the gui to connect these functions.

Hinsbart | 2016-06-24 22:57