Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

pygame.key

A topic by Yair Mizrachi created Jan 14, 2021 Views: 241 Replies: 2
Viewing posts 1 to 3

i know that the mouse button is event.type == pygame.MOUSEBUTTONDOWN

but what is the key code for the left mouse button?

(1 edit) (+1)

If event.button == 1:

        Print("Left button is pressed")

    

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)

#all values are Boolean
Each one is a boolean integer representing button up/down.

You can do like this:

Left, scroll,right = pygame.mouse.get_pressed()

Reset all three values once event handling is done. You can even store for scroll too.

Eg: left, scroll , right, scrollup , scrolldown = pygame.mouse.get_pressed()

Host

Sujal gives a good answer to your question.
However, if you have questions please it would be better if you asked them on the pygame community discord server. You will get answers more quickly from more people:
https://discord.gg/A9nErTcTaN