您可以为文档中概述的场景编写代码(按钮2鼠标中键在按钮1和3按下时触发)。在mouse_pressed = pygame.mouse.get_pressed()
if (mouse_pressed[0] and mouse_pressed[2]) or mouse_pressed[1]:
print("left and right clicked")
记住,使用pygame.mouse.get_按下()通常会触发得非常快,这意味着if语句中的任何代码都将在释放鼠标键之前发生几次。这是因为get_pressed()始终返回所有鼠标按钮的状态。如果你想跟踪被按下的按钮,这个方法是很好的。在
我会把解决方案编码到pygame.event.get(). 这只会在事件发生时触发,因此只有一次:
^{pr2}$
更新-在两个按钮的鼠标上模拟第三次鼠标点击
上面的代码可以工作,但是只有如果您接受这样一个事实,即单个的right或left操作也将触发,但是在combo(left/right)操作之前。如果这对你的游戏设计有用,那就试试吧。如果这是不可接受的,那么以下方法将起作用(尽管更深入一些):left_mouse_down = False
right_mouse_down = False
left_click_frame = 0 # keeps track of how long the left button has been down
right_click_frame = 0 # keeps track of how long the right button has been down
left_right_action_once = True # perform the combo acti