如何检测用户是否在 pygame 中双击了?

问题描述:

我知道我可以检查是否有左键点击

I know I can check if there was a left click

event.type == pygame.MOUSEBUTTONDOWN and event.button == LEFT

但是我如何检查他们是否双击了?还有什么方法可以检查用户是向前还是向后移动滚轮?

but how can I check if they double clicked? Also is there any way to check if the user moved the scroll wheel forward or backwards?

我从未使用过 pygame - 但是:

I've never used pygame - but:

  • 检测双击: 猜测一下,不是立即处理每次点击,而是应用 50 毫秒的延迟,看看在那段时间是否有另一个点击事件.用户可能不会注意到 50 毫秒的延迟.

  • Detecting double clicks: at a guess, instead of processing each click immediately, apply a 50ms delay and see if you get another click event in that time. The user probably won't notice the 50ms delay.

区分向上/向下滚轮:查看关于此文档页面. 显然定义了五个按钮 - 左、中、右、滚轮向上和滚轮向下.也就是说,您可以像捕获左键单击一样捕获滚轮事件 - 您只需要查找 SCROLL_UP 或类似的而不是 LEFT.

Distinguishing between scrollwheel up/down: see the comments on this documentation page. Apparently there are five buttons defined - left, middle, right, scrollwheel-up and scrollwheel-down. That is, you can capture scrollwheel events the same way you're capturing left clicks - you just need to look for SCROLL_UP or similar instead of LEFT.

查阅文档以确切了解 SCROLL_UP 的名称.

Look up the documentation to find out exactly what SCROLL_UP is called.