pyglet.window.mouse

Mouse constants and utilities for pyglet.window.

class MouseStateHandler

Simple handler that tracks the state of buttons and coordinates from the mouse.

If a button is pressed then this handler holds a True value for it. If the window loses focus, all values will be reset to False in order to avoid a “sticky” state.

For example:

>>> win = window.Window()
>>> mouse_state = mouse.MouseStateHandler()
>>> win.push_handlers(mouse_state)

# Hold down the "left" button...

>>> mouse_state[mouse.LEFT]
True
>>> mouse_state[mouse.RIGHT]
False

Mouse coordinates can be retrieved by using the 'x' and 'y' strings.

For example:

>>> win = window.Window()
>>> mouse_state = mouse.MouseStateHandler()
>>> win.push_handlers(mouse_state)

# Move the mouse around...

>>> mouse_state['x']
20
>>> mouse_state['y']
50
__init__() None
buttons_string(buttons: int) str

Return a string describing a set of active mouse buttons.

Example:

>>> buttons_string(LEFT | RIGHT)
'LEFT|RIGHT'
Parameters:

buttons (int) – Bitwise combination of mouse button constants.

Return type:

str

LEFT

Constant for the left mouse button.

MIDDLE

Constant for the middle mouse button.

MOUSE4

Constant for the mouse4 button.

MOUSE5

Constant for the mouse5 button.

RIGHT

Constant for the right mouse button.