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)

asked Jul 8, 2018 in Engine by Zeero (38 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:

my_button.connect("button_down",self,"on_button_click")

And you have the "on button click" function:

func on_button_click():
     print("hello")

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:

Input.parse_input_event(ie)

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"):
         emit_signal("button_down")

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.

answered Jul 8, 2018 by hinasis (308 points)
edited Jul 8, 2018 by hinasis
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 How to use this Q&A? before posting your first questions.