How to make pressed() button signal happen before focus_entered()?

I have my Restart Button working to Reload the current scene by using the signal pressed(), and added focus_entered() and focus_exit() for the Button Highlights.

I can navigate in the Pause Menu using Arrow Keys to go to Restart Button and press ui_accept to activate pressed(). No problem at all.

But when using touch/mouse click, it automatically activates pressed() instead of highlighting it first. Now I noticed that Godot indeed highlights the button first upon pressing down, and pressed() fires on button down or up depending on the button’s behaviour.

What I want is to highlight the button first when touched/clicked, and then only activates pressed() when it was already highlighted.

I made some workaround like adding a press_counter variable but it doesn’t make sense on the keyboard that a button is already highlighted but you have to press ui_accept twice.

I’d like to make pressed() to happen first so it checks if the button is highlighted, if not, then do not Restart, and then focus_entered() happens to flag the button highlighted, and then press again to Restart.

So you want the player to click the button with the mouse twice before they can restart the scene, but only have to press enter or space on the keyboard once, right? I don’t think there’s a way you can force pressed to be emitted before focus_entered but you can put a timer that starts in the focus_entered function that won’t let you press the button if it’s been too soon since the focus was first entered.

1 Like

Sort of yes. It’s more of like, you need the button highlighted first and not double-click the folder/application to open kind of scenario. It’s basically just like when navigating through the menu when using arrow keys, you highlight the button and press confirm to Restart.

That actually makes way much more sense than putting a press counter on the pressed() function. I already made it in my other menu that checks if the last action is a touch/mouse click or a keyboard press and then checks the counter, so much conditions on single button.

I’ll try to make it work. Thanks.

1 Like

I got it to work with get_tree().create_timer. But I need to set the Button’s Action Mode to Button Press.

Made a workaround that delays the final line in focus_entered by waiting if the button is indeed pressed-released. But it will keep waiting for a press if I’m not using keyboard since it automatically highlights the button without being pressed.

Just wondering if there’s a way to check if Button is Clicked/Touched or Pressed by ui_accept? I want to differentiate if it was touched/mouse clicked then it needs to be touched/mouse clicked twice, or if it’s press via ui_accept, you only need to press space/enter once?

1 Like

There’s no way to distinguish between button press and click for the button’s pressed signal, you’d have to implement your own logic

1 Like

I see. That answers everything. Thank you so much.
I do have a script that checks if the last input is a Keyboard or a Click/Touch before the highlight happens, but it ends up needing to have multiple conditions just for a single button function.

1 Like