Script keypresses in game
-
I'm trying to automate a number of moves with a python script to control my character in game (
lr-gambatte
). As RetroPie/Emulationstation do not rely on X11, most libraries to emulate a virtual keyboard input don't work.The following python3 script (using uinput, https://github.com/tuomasjjrasanen/python-uinput) works in the emulationstation menu, but doesn't in game (
lr-gambatte
).Does anyone have an idea, how to send/emulate keystrokes via a python script that is started via SSH? I'm not opposed to switching the script language.
import time import uinput def main(): events = (uinput.KEY_LEFT, uinput.KEY_DOWN, uinput.KEY_D) with uinput.Device(events) as device: time.sleep(1) device.emit_click(uinput.KEY_LEFT) time.sleep(0.2) device.emit_click(uinput.KEY_D) time.sleep(0.2) device.emit_click(uinput.KEY_DOWN) time.sleep(0.2) if __name__ == "__main__": main()
-
Your script is simulating a virtual keypad/gamepad, but RetroArch may be ignoring the device if it's not properly registered with
udev
as a keyboard.Run
udevadm info -q all /dev/input/eventX
, where/dev/input/eventX
is your device's path, and see if it hasID_INPUT_KEY=1
orID_INPUT_KEYBOARD=1
.You can take a look at https://pypi.org/project/ubox360/ to see a more fleshed out example of simulating an Xbox 360 controller.
-
@mitu Interesting! Thank you very much for your feedback! I'll check how the library emulates the keyboard!
My fallback is a microcontroller to emulate the keyboard, if the software portion is too complex.
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.