You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pygame.mousebuttondown事件各鼠标按钮对应赋值查询

Pygame mousebuttondown 事件鼠标按钮对应值列表

以下是Pygame中mousebuttondown事件里event.button对应的鼠标按键值:

  • 左键:1
  • 中键(滚轮按下):2
  • 右键:3
  • 向前侧键(部分鼠标支持):4
  • 向后侧键(部分鼠标支持):5

简单示例代码

import pygame
pygame.init()
screen = pygame.display.set_mode((400, 300))

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            exit()
        elif event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:
                # 处理左键点击逻辑
                pass
            elif event.button == 3:
                # 处理右键点击逻辑
                pass

内容的提问来源于stack exchange,提问作者cinde

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 12:35:21