0 votes

Is there any way to Trigger Buttons like if I press it with my mouse? Currently I want to literally CLOSE a "Tabs" tab by script, but emitting the closed signal seems to do exactly what it is meant to: just signs that it was closed, but don't actually close it, so there's no way to close a tab except clicking it's close button, that we don't have access (at least clearly)

Anyone knows how could this be achieved, or if this is subject to open an issue for? (at least have access to "Tabs" close button)

in Engine by (40 points)

1 Answer

0 votes

Isn't it enough just using remove_tab method?
If not, and you need to simulate a click on a button:

Lets think you connect your "my_button" button like this:


And you have the "on button click" function:

func on_button_click():

First create an InputEventAction and set an action name you are not using in your InputMaps, for example "custom_action", and set it pressed:

var ie = InputEventAction.new()
ie.action = "custom_action"
ie.pressed = true

Then parse it to Input to be handled:


Now in the button, override input method and make it emit the "button down" signal that you connected to the method that handles the button click, when the "custom_action" event reaches Input:

func _input(event):
    if event.is_action_pressed("custom_action"):

That's all, every time you want to emulate the click, parse the custom event to Input.

EDIT: Well, you actually need to register the action in the InputMap on your project setting to avoid errors on debug.

by (327 points)
edited by
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.