how to get the mouse input in pygame

if event.type == pygame.MOUSEBUTTONDOWN:
    print(event.button)
    
#------------------------#
1 - left click
2 - middle click
3 - right click
4 - scroll up
5 - scroll down
#------------------------#

Here is what the above code is Doing:
1. First, we import the pygame library.
2. Then, we initialize pygame.
3. Next, we create a screen with the size of 640 by 480 pixels.
4. After that, we create a while loop that will run forever.
5. Inside the while loop, we check if the event is equal to pygame.QUIT.
6. If it is, then we break out of the while loop.
7. If the event is equal to pygame.MOUSEBUTTONDOWN, then we print the event.button.
8. Finally, we update the screen.

Now, if you run the code, you should see the following output:

1
2
3
4
5

You can also use the pygame.mouse.get_pressed() function to get the state of the mouse buttons.

The pygame.mouse.get_pressed() function returns a tuple of three values:

1. The first value is 1 if the left mouse button is pressed, otherwise it is 0.
2. The second value is 1 if the middle mouse button is pressed, otherwise it is 0.
3. The third value is 1 if the right mouse button is pressed, otherwise it is 0.

Here’s an example:

import pygame

pygame.init()

screen = pygame.display.set_mode((640, 480))

while True:

for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()

(pressed1, pressed2, pressed3) = pygame.mouse.get_pressed()

if pressed1:
print(“Left button is pressed”)
if pressed2:
print(“Middle button is pressed”)
if pressed3:
print(“Right button is pressed”)

pygame.display.update()

If you run the code, you should see the following output:

Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed
Left button is pressed