|
123456789101112131415161718192021222324252627282930 |
- #!/usr/bin/env python
-
- from RPi import GPIO
- import time
- from subprocess import call
-
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(3, GPIO.IN)
-
- pressed = False
-
- shutdown = 2.5
- press_start = time.time()
-
- while True:
- current = not GPIO.input(3)
-
- if current and not pressed:
- call(["xdotool", "keydown", "Escape"])
- pressed = True
- press_start = time.time()
- elif not current and pressed:
- call(["xdotool", "keyup", "Escape"])
- pressed = False
-
- if current:
- if time.time() - shutdown >= press_start:
- call(["sudo", "shutdown", "-h", "now"])
-
- time.sleep(0.1)
|