Pygame.mousebuttondown中的每个鼠标按钮都分配了什么



我正在尝试制作一款游戏,到目前为止,我在标题屏幕上只有一个按钮。但是,我不知道为每个按钮指定了哪些值。请回复分配给鼠标按钮的鼠标按钮的完整列表,这样我就不用再问了

如果文档难以理解、不完整或不透明,您可以随时检查自己。

下面是一个可以用来打印每次按下鼠标按钮时生成的事件的最小示例:

import pygame
pygame.init()
width, height = 640, 480
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Mouse Button Test")
clock = pygame.time.Clock()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.MOUSEBUTTONDOWN:
print(event)
pygame.display.update()
clock.tick(60)
pygame.quit()

当您点击屏幕时,您的控制台将显示事件的详细信息。例如,对于左键单击、右键单击、中键单击、向上滚动、向下滚动,我看到了以下内容:

pygame 2.1.2 (SDL 2.0.18, Python 3.9.13)
Hello from the pygame community. https://www.pygame.org/contribute.html
<Event(1025-MouseButtonDown {'pos': (131, 134), 'button': 1, 'touch': False, 'window': None})>
<Event(1025-MouseButtonDown {'pos': (131, 134), 'button': 3, 'touch': False, 'window': None})>
<Event(1025-MouseButtonDown {'pos': (131, 134), 'button': 2, 'touch': False, 'window': None})>
<Event(1025-MouseButtonDown {'pos': (131, 134), 'button': 4, 'touch': False, 'window': None})>
<Event(1025-MouseButtonDown {'pos': (131, 134), 'button': 5, 'touch': False, 'window': None})>

最新更新