gpt4 book ai didi

python - MOUSEBUTTONDOWN 事件没有响应 [pygame]

转载 作者:行者123 更新时间:2023-12-03 23:42:39 24 4
gpt4 key购买 nike

时,我无法检测到该事件鼠标按键 按下 .
在问这个问题之前,我试过:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com