当 时,我无法检测到该事件鼠标按键 是 按下 .
在问这个问题之前,我试过:
import pygame, sys
pygame.init()
win = pygame.display.set_mode((1260, 960))
pygame.display.set_caption("PONG")
finish = False
fps = 60
clock = pygame.time.Clock()
while not finish:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.MOUSEBUTTONDOWN:
print('MOUSE BUTTON PRESSED DOWN')
clock.tick(fps)
pygame.display.update()
代码有什么问题?另外,我的终端中没有任何错误。
最佳答案
看看documentation .
QUIT none
ACTIVEEVENT gain, state
KEYDOWN key, mod, unicode, scancode
KEYUP key, mod
MOUSEMOTION pos, rel, buttons
MOUSEBUTTONUP pos, button
MOUSEBUTTONDOWN pos, button
JOYAXISMOTION joy (deprecated), instance_id, axis, value
JOYBALLMOTION joy (deprecated), instance_id, ball, rel
JOYHATMOTION joy (deprecated), instance_id, hat, value
JOYBUTTONUP joy (deprecated), instance_id, button
JOYBUTTONDOWN joy (deprecated), instance_id, button
VIDEORESIZE size, w, h
VIDEOEXPOSE none
USEREVENT code
您正在寻找 MOUSEBUTTONDOWN
事件,而不是 KEYDOWN
:for event in pygame.event.get():
...
if event.type == pygame.MOUSEBUTTONDOWN:
print('MOUSE BUTTON PRESSED DOWN')
关于python - MOUSEBUTTONDOWN 事件没有响应 [pygame],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64854605/