Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中为按下按钮进行冷却_Python_Time_Keyboard - Fatal编程技术网

如何在python中为按下按钮进行冷却

如何在python中为按下按钮进行冷却,python,time,keyboard,Python,Time,Keyboard,我需要一种方法,如果你按下键盘上的一个按钮,按下这个按钮会有一个冷却时间。 我正在使用键盘模块 import keyboard a=0 while a==a if keyboard.is_pressed('space'): print("The spacebar was pressed! ") #Now I want it to wait for 1s until you can press the spacebar again 请回答 您希望冷却时

我需要一种方法,如果你按下键盘上的一个按钮,按下这个按钮会有一个冷却时间。 我正在使用键盘模块

import keyboard
a=0
while a==a
    if keyboard.is_pressed('space'):
        print("The spacebar was pressed! ")
#Now I want it to wait for 1s until you can press the spacebar again

请回答

您希望冷却时间在哪里?在脚本中?节省您按下它的时间。每次按下检查,如果你最后一次按下的时间超过1秒(或者不管你的冷却时间是什么),你能告诉我怎么做吗?我更新了问题,这样你现在就可以更好地理解它了。