如何通过诸如 之类的按键来打破这个循环Esc?此示例捕获击键,但从未将变量传递到 while 循环中。
from pynput import keyboard
count = 0
stop = 0
while True:
def press_callback(key):
if key == keyboard.Key.esc:
def stop_loop():
stop = 1
return stop
print('You pressed "escape"! You must want to quit really badly...')
stop = stop_loop()
return stop
count +=1
print (count)
if stop == 1:
break
if count == 1:
l = keyboard.Listener(on_press=press_callback)
l.start()
我使用的是 Ubuntu 18.04。
暮色呼如
芜湖不芜
相关分类