Pygame获取鼠标球信息

Pygame get information about mouse ball

有没有办法获取有关鼠标球的信息,看看它是向上滚动还是向下滚动。使用 pygame.mouse.get_pressed()pygame.MOUSEBUTTONDOWN / UP 仅提供有关鼠标单击的信息,而不提供有关球滚动的信息。

可以从 MOUSEBUTTONDOWN 事件按钮属性调用每个鼠标按钮事件。包括 left/right/middle 单击并向下滚动 up/scroll

示例:

import pygame as py

py.init()

window = (400,400)
screen = py.display.set_mode(window)

clock = py.time.Clock()

done = False
while not done:
    for event in py.event.get():
        if event.type == py.QUIT:
            done = True
        elif event.type == py.MOUSEBUTTONDOWN:
            if event.button == 4:
                print "scrolled up"
            elif event.button == 5:
                print "scrolled down"
    clock.tick(30)

py.quit()

这会在活动 window 中查找按下的鼠标按钮并在向上或向下滚动时打印