I'm trying to make a game, and so far I have one button on the title screen. However, I do not know which values are assigned to each button. Please respond with a full list of mousebuttondown buttons assigned to mouse buttons, so I'm not going to have to ask again
Asked
Active
Viewed 159 times
-2
-
Please see: https://www.pygame.org/docs/ref/mouse.html#pygame.mouse.get_pressed – Kingsley Oct 11 '22 at 23:22
-
it doesn't tell you which buttons are assigned to which (like left/right click) – cinde Oct 11 '22 at 23:43
-
There is no *rule* about which button is which. This is not a PyGame thing, but a Mouse thing. The typical convention is that `1` is left, `2` is right, `3` is middle-mouse (or scroll-wheel click (not scroll)). But imagine something like a 5-button mouse, or a tap on a touch-screen, or tap on a laptop touch pad, or double-tap, or multi-finger touches. You can't pre-define how all these current and up-coming technologies will resolve when considered as a mouse click. It's hardware dependant. – Kingsley Oct 12 '22 at 00:22
-
1Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Oct 12 '22 at 06:32
1 Answers
0
If the documentation is difficult to understand or incomplete or opaque, you can always inspect yourself.
Here's a minimal example that you can use to print the events that are generated with each mouse button press:
import pygame
pygame.init()
width, height = 640, 480
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Mouse Button Test")
clock = pygame.time.Clock()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.MOUSEBUTTONDOWN:
print(event)
pygame.display.update()
clock.tick(60)
pygame.quit()
When you click in the screen, your console will show the event details. E.g., for left click, right-click, middle click, scroll up, scroll down I saw the following:
pygame 2.1.2 (SDL 2.0.18, Python 3.9.13)
Hello from the pygame community. https://www.pygame.org/contribute.html
<Event(1025-MouseButtonDown {'pos': (131, 134), 'button': 1, 'touch': False, 'window': None})>
<Event(1025-MouseButtonDown {'pos': (131, 134), 'button': 3, 'touch': False, 'window': None})>
<Event(1025-MouseButtonDown {'pos': (131, 134), 'button': 2, 'touch': False, 'window': None})>
<Event(1025-MouseButtonDown {'pos': (131, 134), 'button': 4, 'touch': False, 'window': None})>
<Event(1025-MouseButtonDown {'pos': (131, 134), 'button': 5, 'touch': False, 'window': None})>

import random
- 3,054
- 1
- 17
- 22