pygame documentation | || Home || Help Contents || || pygame || cdrom || constants || display || draw || event || || font || image || joystick || key || mixer || mixer_music || || mouse || movie || sndarray || surfarray || time || transform || || CD || Channel || Clock || Font || Joystick || Movie || || Rect || Sound || Surface || || color || cursors || sprite ||

## pygame.mouse

Contains routines for dealing with the mouse. All mouse events are retrieved through the pygame.event module. The mouse module can be used to get the current state of the mouse. It can also be used to set the state of the system cursor.
If you hide the mouse cursor with pygame.mouse.set_visible(0) and lock the mouse focus to your game with pygame.event.set_grab(1), the hidden mouse will be forced to the center of the screen. This will help your relative mouse motions keep from getting stuck on the edges of the screen.

get_cursor | - get mouse cursor data
get_focused | - state of mouse input focus
get_pos | - gets the cursor position
get_pressed | - state of the mouse buttons
get_rel | - gets the movement of the mouse
set_cursor | - state of shape of the mouse cursor
set_pos | - moves the cursor position
set_visible | - show or hide the mouse cursor

get_cursor
`pygame.mouse.get_cursor() -> size, hotspot, xormasks, andmasks`

The mouse cursor data is the same as those passed into set_cursor.

get_focused
`pygame.mouse.get_focused() -> bool`

Returns true when the application is receiving the mouse input focus.

get_pos
`pygame.mouse.get_pos() -> x, y`

Returns the current position of the mouse cursor. This is the absolute mouse position inside your game window.

get_pressed
`pygame.mouse.get_pressed() -> button1, button2, button3`

This will return a small sequence containing the pressed state of each mouse button.

get_rel
`pygame.mouse.get_rel() -> x, y`

Returns the total distance the mouse has moved since your last call to get_rel(). On the first call to get_rel the movement will always be 0,0.
When the mouse is at the edges of the screen, the relative movement will be stopped. See mouse_visible for a way to resolve this.

set_cursor
`pygame.mouse.set_cursor(size, hotspot, xormasks, andmasks) -> None`

When the mouse cursor is visible, it will be displayed as a black and white bitmap using the given bitmask arrays. The size is a sequence containing the cursor width and height. Hotspot is a sequence containing the cursor hotspot position. xormasks is a sequence of bytes containing the cursor xor data masks. Lastly is andmasks, a sequence of bytes containting the cursor bitmask data.
Width must be a multiple of 8, and the mask arrays must be the correct size for the given width and height. Otherwise an exception.

set_pos
`pygame.mouse.set_pos(pos) -> None`

Moves the mouse cursor to the specified position. This will generate a MOUSEMOTION event on the input queue. The pos argument is a 2-number-sequence containing the desired x and y position.

set_visible
`pygame.mouse.set_visible(bool) -> bool`

Shows or hides the mouse cursor. This will return the previous visible state of the mouse cursor.
Note that when the cursor is hidden and the application has grabbed the input. pygame will force the mouse to stay in the center of the screen. Since the mouse is hidden it won't matter that it's not moving, but it will keep the mouse from the edges of the screen so the relative mouse position will always be true.