Skip to content

Commit d6e61c9

Browse files
authored
Enhance pygame.mouse.get_pressed docs (#3084)
* Enhance mouse docs * Add pygame.event.pump * Remove BUTTON_* note
1 parent f1bd7f3 commit d6e61c9

File tree

1 file changed

+37
-39
lines changed

1 file changed

+37
-39
lines changed

docs/reST/ref/mouse.rst

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ When the display mode is set, the event queue will start receiving mouse
1515
events. The mouse buttons generate ``pygame.MOUSEBUTTONDOWN`` and
1616
``pygame.MOUSEBUTTONUP`` events when they are pressed and released. These
1717
events contain a button attribute representing which button was pressed. The
18-
mouse wheel will generate ``pygame.MOUSEBUTTONDOWN`` and
19-
``pygame.MOUSEBUTTONUP`` events when rolled. The button will be set to 4
20-
when the wheel is rolled up, and to button 5 when the wheel is rolled down.
21-
Whenever the mouse is moved it generates a ``pygame.MOUSEMOTION`` event. The
22-
mouse movement is broken into small and accurate motion events. As the mouse
23-
is moving many motion events will be placed on the queue. Mouse motion events
24-
that are not properly cleaned from the event queue are the primary reason the
18+
mouse wheel will generate ``pygame.MOUSEBUTTONDOWN`` and
19+
``pygame.MOUSEBUTTONUP`` events when rolled. The button will be set to 4
20+
when the wheel is rolled up, and to button 5 when the wheel is rolled down.
21+
Whenever the mouse is moved it generates a ``pygame.MOUSEMOTION`` event. The
22+
mouse movement is broken into small and accurate motion events. As the mouse
23+
is moving many motion events will be placed on the queue. Mouse motion events
24+
that are not properly cleaned from the event queue are the primary reason the
2525
event queue fills up.
2626

2727
If the mouse cursor is hidden, and input is grabbed to the current display the
@@ -34,17 +34,17 @@ configured.
3434
**Mouse Wheel Behavior in pygame 2**
3535

3636
There is proper functionality for mouse wheel behaviour with pygame 2 supporting
37-
``pygame.MOUSEWHEEL`` events. The new events support horizontal and vertical
38-
scroll movements, with signed integer values representing the amount scrolled
39-
(``x`` and ``y``), as well as ``flipped`` direction (the set positive and
40-
negative values for each axis is flipped). Read more about SDL2
37+
``pygame.MOUSEWHEEL`` events. The new events support horizontal and vertical
38+
scroll movements, with signed integer values representing the amount scrolled
39+
(``x`` and ``y``), as well as ``flipped`` direction (the set positive and
40+
negative values for each axis is flipped). Read more about SDL2
4141
input-related changes here `<https://wiki.libsdl.org/MigrationGuide#input>`_
4242

43-
In pygame 2, the mouse wheel functionality can be used by listening for the
44-
``pygame.MOUSEWHEEL`` type of an event (Bear in mind they still emit
43+
In pygame 2, the mouse wheel functionality can be used by listening for the
44+
``pygame.MOUSEWHEEL`` type of an event (Bear in mind they still emit
4545
``pygame.MOUSEBUTTONDOWN`` events like in pygame 1.x, as well).
46-
When this event is triggered, a developer can access the appropriate ``Event`` object
47-
with ``pygame.event.get()``. The object can be used to access data about the mouse
46+
When this event is triggered, a developer can access the appropriate ``Event`` object
47+
with ``pygame.event.get()``. The object can be used to access data about the mouse
4848
scroll, such as ``which`` (it will tell you what exact mouse device trigger the event).
4949

5050
.. code-block:: python
@@ -57,19 +57,19 @@ scroll, such as ``which`` (it will tell you what exact mouse device trigger the
5757
pygame.init()
5858
screen = pygame.display.set_mode((640, 480))
5959
clock = pygame.time.Clock()
60-
60+
6161
def main():
6262
while True:
6363
for event in pygame.event.get():
6464
if event.type == QUIT:
6565
pygame.quit()
6666
return
6767
elif event.type == MOUSEWHEEL:
68-
print(event)
68+
print(event)
6969
print(event.x, event.y)
7070
print(event.flipped)
7171
print(event.which)
72-
# can access properties with
72+
# can access properties with
7373
# proper notation(ex: event.y)
7474
clock.tick(60)
7575
@@ -86,23 +86,21 @@ scroll, such as ``which`` (it will tell you what exact mouse device trigger the
8686
buttons. A true value means the mouse is currently being pressed at the time
8787
of the call.
8888

89-
Note, to get all of the mouse events it is better to use either
90-
``pygame.event.wait()`` or ``pygame.event.get()`` and check all of those
89+
To get all of the mouse events it is better to use either
90+
``pygame.event.wait()`` or ``pygame.event.get()`` and check all of those
9191
events to see if they are ``MOUSEBUTTONDOWN``, ``MOUSEBUTTONUP``, or
92-
``MOUSEMOTION``.
92+
``MOUSEMOTION``. Remember to call ``pygame.event.get()`` or ``pygame.event.pump()``
93+
before this function, otherwise it will not work as expected.
9394

94-
Note, that on ``X11`` some X servers use middle button emulation. When you
95-
click both buttons ``1`` and ``3`` at the same time a ``2`` button event
96-
can be emitted.
95+
To support five button mice, an optional parameter ``num_buttons`` has been
96+
added in pygame 2. When this is set to ``5``, ``button4`` and ``button5``
97+
are added to the returned tuple. Only ``3`` and ``5`` are valid values
98+
for this parameter.
9799

98-
Note, remember to call ``pygame.event.get()`` before this function.
99-
Otherwise it will not work as expected.
100+
.. note:: On ``X11`` some X servers use middle button emulation. When you
101+
click both buttons ``1`` and ``3`` at the same time a ``2`` button event
102+
can be emitted.
100103

101-
To support five button mice, an optional parameter ``num_buttons`` has been
102-
added in pygame 2. When this is set to ``5``, ``button4`` and ``button5``
103-
are added to the returned tuple. Only ``3`` and ``5`` are valid values
104-
for this parameter.
105-
106104
.. versionchangedold:: 2.0.0 ``num_buttons`` argument added
107105

108106
.. ## pygame.mouse.get_pressed ##
@@ -113,18 +111,18 @@ scroll, such as ``which`` (it will tell you what exact mouse device trigger the
113111
| :sg:`get_just_pressed() -> (left_button, middle_button, right_button, x1_button, x2_button)`
114112
115113
Very similar to :func:`pygame.mouse.get_pressed()`, returning a tuple
116-
of length 5 with the important difference that the buttons are
114+
of length 5 with the important difference that the buttons are
117115
True only in the frame they start being pressed. This can be convenient
118116
for checking the buttons pressed "this frame", but for more precise results
119-
and correct ordering prefer using the pygame.MOUSEBUTTONDOWN event.
117+
and correct ordering prefer using the ``pygame.MOUSEBUTTONDOWN`` event.
120118

121119
The result of this function is updated when new events are processed,
122120
e.g. in :func:`pygame.event.get()` or :func:`pygame.event.pump()`.
123121

124122
.. seealso:: :func:`pygame.mouse.get_just_released()`
125123

126124
::
127-
125+
128126
if pygame.mouse.get_just_pressed()[0]:
129127
print("LMB just pressed")
130128

@@ -138,18 +136,18 @@ scroll, such as ``which`` (it will tell you what exact mouse device trigger the
138136
| :sg:`get_just_released() -> (left_button, middle_button, right_button, x1_button, x2_button)`
139137
140138
Similar to :func:`pygame.mouse.get_pressed()`, returning a tuple
141-
of length 5 with the important difference that the buttons are
139+
of length 5 with the important difference that the buttons are
142140
True only in the frame they stop being pressed. This can be convenient
143141
for checking the buttons released "this frame", but for more precise results
144-
and correct ordering prefer using the pygame.MOUSEBUTTONUP event.
142+
and correct ordering prefer using the ``pygame.MOUSEBUTTONUP`` event.
145143

146144
The result of this function is updated when new events are processed,
147145
e.g. in :func:`pygame.event.get()` or :func:`pygame.event.pump()`.
148146

149147
.. seealso:: :func:`pygame.mouse.get_just_pressed()`
150148

151149
::
152-
150+
153151
if pygame.mouse.get_just_released()[0]:
154152
print("LMB just released")
155153

@@ -258,7 +256,7 @@ scroll, such as ``which`` (it will tell you what exact mouse device trigger the
258256
Get the information about the mouse system cursor. The return value contains
259257
the same data as the arguments passed into :func:`pygame.mouse.set_cursor()`.
260258

261-
.. note:: Code that unpacked a get_cursor() call into
259+
.. note:: Code that unpacked a get_cursor() call into
262260
``size, hotspot, xormasks, andmasks`` will still work,
263261
assuming the call returns an old school type cursor.
264262

@@ -285,7 +283,7 @@ scroll, such as ``which`` (it will tell you what exact mouse device trigger the
285283
Sets the relative mouse mode state.
286284
While the mouse is in relative mode, the cursor is hidden,
287285
the mouse position is constrained to the window, and pygame
288-
will report continuous relative mouse motion even if the
286+
will report continuous relative mouse motion even if the
289287
mouse is at the edge of the window.
290288

291289
*This function will flush any pending mouse motion."*

0 commit comments

Comments
 (0)