1

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()
R Yoda
  • 8,358
  • 2
  • 50
  • 87

1 Answers1

2

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")
  • 1
    Damn easy, I should have known this, it is documented in the API: https://pygame-zero.readthedocs.io/en/stable/hooks.html#on_mouse_down – R Yoda Oct 06 '19 at 18:15