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

ERJAN picture ERJAN · Dec 15, 2015 · Viewed 30.6k times · Source

From api of pygame, it has:

event type.MOUSEBUTTONDOWN, MOUSEBUTTONUP, MOUSEMOTION

But there is no way to distinguish between right, left clicks?

Answer

Spooky picture Spooky · Dec 16, 2015
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


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

pygame.mouse.get_pressed()

This returns a tuple:

(leftclick, middleclick, rightclick)

Each one is a boolean integer representing button up/down.