The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+1 vote

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?


in Engine by (549 points)

2 Answers

0 votes

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 clickonpress 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).

by (9,800 points)

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.

0 votes

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")
by (1,320 points)

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).

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

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.