Search code examples
pythonpgzero

on_mouse_down called for every button (even scroll wheel movements)


I am using pgzero for implementing a game and have found out that the on_mouse_down hook function is even called when I move/roll the scroll wheel. This is surprising.

How can I prevent this?

import pgzrun
import pgzero

def on_mouse_down(pos):
    print("mouse down hook called")

pgzrun.go()

Solution

  • on_mouse_down takes more parameters than you're currently getting. The second one is the button:

    def on_mouse_down(pos, button):
        if button == mouse.LEFT:
            print("mouse down hook called")