Can I programmatically press keyboard key?

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

Hello,

I´m working on support application for a diffrent game and I need to simulate keyboard press. I know I can simulate keypress inside of application, but I´m looking for something like SendKeys Class.

Is it possible?

Thanks

AFAIK it is not possible without a plugin and AFAIK there is no plugin for that yet.
What are you trying to do? Maybe there is another way.

whiteshampoo | 2021-03-31 08:59

Thanks for reply!

It should be the dashboard app for ETS 2. One part is an Android app that recieving telemetry via plugin and draw it to the cluster. Second part is server on PC that provide communication between app and game. So one way (from game to android) is working fine. But I want to made it the other way too, so when you press a button on android, it should call the keypress on PC.

Michael721 | 2021-03-31 11:17

Maybe you could hack something with OS.execute and a python-script with pyautogui.

whiteshampoo | 2021-03-31 12:19

:bust_in_silhouette: Reply From: Wakatta

Godot is a game engine and not a windows manager or macro tool so it’ll be very demanding to expect such functionalities from it out of the box.

On windows it would be better to use AutoHotkey for something like this but if you insist on using Godot the same can be achieved using vbScripts with cscrip.exe and OS.execute

Since csript is part of the global path you should be able to use it without defining it’s absolute path

:bust_in_silhouette: Reply From: tomo

Input.action_press() function might help you.

For example, this simulates space-key input

Input.action_press("ui_accept")

You also should check Input.parse_input_event() function.