How to distinguish left click , right click mouse clicks in pygame? [duplicate]

Click events


if event.type == pygame.MOUSEBUTTONDOWN:
    print(event.button)

event.button can equal several integer values:

1 - left click
2 - middle click
3 - right click
4 - scroll up
5 - scroll down

Fetching mouse state


Instead of waiting for an event, you can get the current button state as well:

state = pygame.mouse.get_pressed()

This returns a tuple in the form: (leftclick, middleclick, rightclick)

Each value is a boolean integer representing whether that button is pressed.

Leave a Comment