#!/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 while True: current = not GPIO.input(3) if current and not pressed: call(["xdotool", "keydown", "Escape"]) pressed = True elif not current and pressed: call(["xdotool", "keyup", "Escape"]) pressed = False time.sleep(0.1)