def event_loop(self):
"""main loop. sets up the GPIO callback then polls the hit state to detect a key press.
"""
self.key_down=False
key_up_sent=False
key_down_sent=False
GPIO.add_event_detect(BtkGpioClient.PIN, GPIO.BOTH, callback=self.pin_event,bouncetime=250)
while True:
if(self.key_down ):
#the pin is set on
if(BtkGpioClient.REPEAT_KEY and key_down_sent):
#finish the current key and repeat
self.send_key_up()
key_down_sent=False
time.sleep(BtkGpioClient.REPEAT_KEY_DELAY)
if(not key_down_sent):
#start a key press
self.send_key_down()
key_down_sent=True
else:
#the pin is set off
if(key_down_sent):
#finish the key press
self.send_key_up()
key_down_sent=False
time.sleep(BtkGpioClient.MIN_KEY_TIME) #seems like the minimum delay required for a keypress to be registered
评论列表
文章目录