libretro / gambatte-libretro

Hard fork of Gambatte to the libretro API.
http://sourceforge.net/projects/gambatte/
GNU General Public License v2.0
104 stars 78 forks source link

Automate/script keystrokes user input for running games #228

Open emma-makes opened 2 years ago

emma-makes commented 2 years ago

I'm writing a bot to automate some movement with a python script in a running rom. I'm using RetroPie/Emulationstation to run lr-gambatte and those projects 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). I start the script via SSH as root.

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()
cyberic99 commented 2 years ago

@emma-makes this project https://github.com/jkotlinski/lsdpack uses libgambatte and sends keystrokes to a headless stripped down gambatte.

not sure it will fit your needs

emma-makes commented 2 years ago

@emma-makes this project https://github.com/jkotlinski/lsdpack uses libgambatte and sends keystrokes to a headless stripped down gambatte.

not sure it will fit your needs

Thank you for bringing this to my attention. That might be a crude hack, but I'll keep it in mind as a last resort approach. I hope to find a scriptable library designed to send keyboard input, which is accepted by retroarch.