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

esc-button.py 420B

12345678910111213141516171819202122
  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. while True:
  9. current = not GPIO.input(3)
  10. if current and not pressed:
  11. call(["xdotool", "keydown", "Escape"])
  12. pressed = True
  13. elif not current and pressed:
  14. call(["xdotool", "keyup", "Escape"])
  15. pressed = False
  16. time.sleep(0.1)