您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930
  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 = 2.5
  9. press_start = time.time()
  10. while True:
  11. current = not GPIO.input(3)
  12. if current and not pressed:
  13. call(["xdotool", "keydown", "Escape"])
  14. pressed = True
  15. press_start = time.time()
  16. elif not current and pressed:
  17. call(["xdotool", "keyup", "Escape"])
  18. pressed = False
  19. if current:
  20. if time.time() - shutdown >= press_start:
  21. call(["sudo", "shutdown", "-h", "now"])
  22. time.sleep(0.1)