Python 3.x 如何检测用户在pygame中是否双击了空格键?
我不熟悉python和pygame。有人能帮我一下吗。Python 3.x 如何检测用户在pygame中是否双击了空格键?,python-3.x,pygame,Python 3.x,Pygame,我不熟悉python和pygame。有人能帮我一下吗。 提前感谢此代码对我有效 global clock, double_click_event, timer double_click_event = pygame.USEREVENT + 1 timer = 0 for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.
提前感谢此代码对我有效
global clock, double_click_event, timer
double_click_event = pygame.USEREVENT + 1
timer = 0
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key==pygame.K_SPACE:
if timer == 0:
pygame.time.set_timer(double_click_event, 500)
timerset = True
x, y = pyautogui.position()
pyautogui.click(x, y, button='left')
else:
if timer == 1:
pygame.time.set_timer(double_click_event, 0)
double_click()
timerset = False
if timerset:
timer = 1
else:
timer = 0
这将使用
tkinter
,但您可以尝试以下方法:
from tkinter import *
tk = Tk()
def helloworld(event):
print('Hello world!')
tk.bind_all('<Double-Button-1>', helloworld)
从tkinter导入*
tk=tk()
def helloworld(事件):
打印(“你好,世界!”)
绑定所有(“”,helloworld)
抱歉,这使用了左键单击,但我希望它能回答。
您可以在函数中执行任何代码,只需确保不使用括号。可能重复我已为链接问题添加了另一个答案。代码似乎无法正常工作。我仍然可以在任意时间后双击。另外,什么是pyautogui?@skrx pyautogui是一个自动化库。