Question

I'm currently designing a script that will, in the end, control a range of games with the ability to start and stop them all from the main script.

However, one of the games can only gracefully stop by pressing the 'ESC' key. How can I interpret this into a signal or something similar?

*The games are started with gamename.Popen() and then usually stopping is done by sending SIGINT or SIGQUIT.

Ideas?

Was it helpful?

Solution

However, one of the games can only gracefully stop by pressing the 'ESC' key. How can I interpret this into a signal or something similar?

You can't. You're trying to cover for a design error in a child process which I suspect grabs its own input and doesn't use the stdin which would allow you to to send an Esc. Let me know if this assumption is incorrect.

Have you tried using SIGTERM with this game? That's the more conventional "clean yourself up and exit" signal, and I can well imagine someone writing code to handle SIGTERM gracefully while leaving SIGINT and SIGQUIT to their defaults.

OTHER TIPS

If you are controlling them by using a PIPE to send keystrokes then sending chr(0x1b) should do the trick.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top