How to simulate ui_accept input event?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DenisNP

Hello there.

I am running my HTML5 game on a pretty strange Android-based TV-box device. This device has a remote control with arrows and OK button. So, using arrows I can normally move my focus from button to button in UI. But OK doesn’t work at all. It does not trigger ui_accept event. It has Unknown scancode in fact.

Fortunately, I can catch this OK button in JavaScript (in browser this button normally recognizes as Enter). So, I want to solve it using JavaScript interoperability: check from Godot if OK button was pressed and then simulate exactly ui_accept event.

How can I do this? I use C#.

Input.ActionPress("ui_accept") doesn’t work. And ActionRelease too, as well as its combination.

I believe you want to use Input.parse_input_event()

Input — Godot Engine (stable) documentation in English

timothybrentwood | 2021-12-08 02:00

Unfortunately, it doesn’t work.

Input.ParseInputEvent(new InputEventAction{ Action = "ui_accept", Pressed = true });
GD.Print("Input event");

I see Input event in the console, but current focused button isn’t pressed.

DenisNP | 2021-12-10 19:27

Try adding an _unhandled_input() function to a node to see if the ui_accept input is getting marked as handled in another node preventing it from propagating to your button. For kicks I would also write the Input.parse_input_event() in a gdscript script just to make sure it’s not some weird c# bug.

timothybrentwood | 2021-12-10 20:06

I’ve solved it in a different way. I just recursively find focused button in tree and emit Press signal on it.

DenisNP | 2021-12-13 21:38