I have a python application being used via console on raspberry pi. It run on startup from the rc.local script. The script does something when a GPIO button is pressed, however I also want to have exit when/if the user hits escape. I've tried things with threads, raw_input, etc but cant get it to work. Here is the script now:
#!/usr/bin/python
import RPi.GPIO as GPIO, time, os, subprocess, dropbox, signal, sys, threading
os.system("clear")
def signal_handler(signal, frame):
print('You pressed Ctrl+C!')
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
# GPIO setup
print("Welcome to the PhotoBooth")
while True:
try:
if (GPIO.input(SWITCH)==False):
os.system("clear")
#DO Stuff
except KeyboardInterrupt:
print "Bye"
sys.exit()
How can detect if escape is pressed without requiring a key to be pressed (e.g. raw_input())?
Also - on a related note, using CTRL+C to stop the app works when I run the app manually from the command line but not when it is started from rc.local - hence why I'm looking for the ESC solution.