Pygame获取有关鼠标球的信息

时间:2016-06-09 19:39:09

标签: pygame mouse

有没有办法获取有关鼠标球的信息,所以如果它正在向上或向下滚动。使用pygame.mouse.get_pressed()pygame.MOUSEBUTTONDOWN / UP仅提供有关单击鼠标的信息,但不会提供有关滚动滚动的信息。

1 个答案:

答案 0 :(得分:1)

可以从MOUSEBUTTONDOWN事件按钮属性调用每个鼠标按钮事件。包括左/右/中间点击和向上/向下滚动

示例:

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()

这将在活动窗口中查找按下的鼠标按钮,并在向上或向下滚动时进行打印