Loading

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 i in eventList:
		# Exit
		if i.type == WINDOWCLOSE:
			pygame.quit()
		# Mouse wheel
		if i.type == pygame.MOUSEWHEEL:
			# Do some thing
			print(i.y)

这个时候,i(单个event对象)的y就是鼠标竖直滚动量。i.y为正,即向上滚动;反之,i.y为负。i.y代表滚动量(取决于你的滚轮滚得快还是慢)。

在一些先进的笔记本电脑上,触摸板向左、向右滑动反映在i.x里。具体请参阅Pygame文档。

posted @ 2022-04-25 21:23  immccn123  阅读(498)  评论(0)    收藏  举报