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
Truevalue for it. If the window loses focus, all values will be reset toFalsein 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 or by using'mouse_state.x'and'mouse_state.yattributes.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 # Or... >>> mouse_state.x 20 >>> mouse_state.y 50
- 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.