Pygame的MOUSEWHEEL事件
Pygame 团队在 Pygame 版本1.9.5
加入了事件MOUSEWHEEL
。官方文档是这么说的:
When compiled with SDL2, pygame has these additional events and their attributes.
AUDIODEVICEADDED which, iscapture
AUDIODEVICEREMOVED which, iscapture
FINGERMOTION touch_id, finger_id, x, y, dx, dy
FINGERDOWN touch_id, finger_id, x, y, dx, dy
FINGERUP touch_id, finger_id, x, y, dx, dy
MOUSEWHEEL which, flipped, x, y, touch
MULTIGESTURE touch_id, x, y, pinched, rotated, num_fingers
TEXTEDITING text, start, length
TEXTINPUT text
New in pygame 1.9.5.
Changed in pygame 2.0.2: Fixed amount horizontal scroll (x, positive to the right and negative to the left).
Changed in pygame 2.0.2: The touch attribute was added to all the MOUSE events.
接下来,我会编写一个捕获事件的函数:
def handleEvent():
eventList = pygame.event.get()
for event in eventList:
# Exit
if event.type == WINDOWCLOSE:
pygame.quit()
# Mouse wheel
if event.type == pygame.MOUSEWHEEL:
# Do some thing
print(event.y)
这个时候,event
(单个event对象)的y
就是鼠标竖直滚动量。event.y
为正,即向上滚动;反之,event.y
为负。event.y
代表滚动量(取决于你的滚轮滚得快还是慢)。
在一些先进的笔记本电脑上,触摸板向左、向右滑动反映在event.x
里。具体请参阅Pygame文档。