Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

esc-button.py 604B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python
  2. from RPi import GPIO
  3. import time
  4. from subprocess import call
  5. GPIO.setmode(GPIO.BCM)
  6. GPIO.setup(3, GPIO.IN)
  7. pressed = False
  8. shutdown = 3 * 10
  9. iterations = 0
  10. while True:
  11. current = not GPIO.input(3)
  12. if current and not pressed:
  13. call(["xdotool", "keydown", "Escape"])
  14. pressed = True
  15. elif not current and pressed:
  16. call(["xdotool", "keyup", "Escape"])
  17. pressed = False
  18. iterations = 0
  19. if current:
  20. iterations += 1
  21. if iterations > shutdown:
  22. call(["sudo", "shutdown", "-h", "now"])
  23. time.sleep(0.1)