0 votes

I have this code.

func _click():
   var a = InputEventMouseButton.new()
   a.set_button_index(1)
   a.position = Vector2(520,250)
   a.pressed = true
   get_tree().input_event(a)

func _input(event):
   if Input.is_action_just_pressed("ui_up"):
       _click()

But it does not work.
I would be glad if someone can help.

in Engine by (1,457 points)
retagged by

1 Answer

+2 votes
Best answer
by (3,244 points)
selected by

Thanks for your answer.
Unfortunately I get this error when using it.

 drivers/unix/net_socket_posix.cpp:190 - Socket error: 10054

Did I something wrong?
My code:

func _click():
var a = InputEventMouseButton.new()
a.set_button_index(1)
a.set_pressed(true)
Input.parse_input_event(a)

The error message looks more like the debugger lost the connection to your app. This mostly happened when the app/program fails. (Without a proper error message.)

Maybe it is problematic calling "parse _ input _ event" just at that moment. (I.e. when handling another event)

You could try call_deferred:

 func _click():
     call_deferred("do_a_left_click")

func do_a_left_click:
     var a = InputEventMouseButton.new()
     a.set_button_index(1)
     a.set_pressed(true)
     Input.parse_input_event(a)

It works when using "call_deferred()".

Thanks a lot for your help!!!

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.
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 webmaster@godotengine.org with your username.