I'm working on a "screensaver" python script that automatically cycles through a bunch of MAME roms when my cabinet isn't in use. Each game stays on the screen for X amount of minutes, and if anyone starts playing the game the screensaver script pauses to let the person play. It then kicks in again after X minutes of inactivity. Gets me out of the rut of loading on the same few games every time, and makes the cabinet a bit more dynamic and varied. I can only look at Mr. Do and Ms Pacman so many times, ha.
Everything is working great except when I try to send a keystroke to MAME. For example, to exit a game, I send the ESC key. But for some reason that doesn't work. Ditto with sending mouse clicks. I've tried all sorts of methods but none are working, MAME just ignores the input.
I'm on Linux, Mame 0.175.
I'd also love to send keystrokes to bypass the warning screen (if present). I know I can recompile for that but so far I haven't had any luck compiling.
I don't imagine anyone has any tips?
I've tried pyautogui, xautomator, evdev, subprocess directly, and a few other methods.
#!/usr/bin/python
import subprocess, time
# launch a ROM (adjust paths to taste)
rom_name = "mrdo"
cmd = "/home/wrybread/.attract/mame/mame -rompath $HOME/.attract/mame/roms -skip_gameinfo -autosave %s" % rom_name
print cmd
p = subprocess.Popen(cmd.split(" "), stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
time.sleep(5)
# exit by sending the ESC key via xautomator
p2 = subprocess.Popen(['xte'], stdin=subprocess.PIPE)
p2.communicate(input="key Escape ") # not sure why need space after string