Contains routines for dealing with the mouse.


  • pygame.mouse.set_pos(pos) -> None
  • - moves the cursor position
  • pygame.mouse.get_pos() -> (x, y)
  • - gets the cursor position
  • pygame.mouse.get_rel() -> (x, y)
  • - gets the movement of the mouse
  • get_pressed() -> (button1, button2, button3)
  • - state of the mouse buttons
  • pygame.mouse.set_visible(bool) -> bool
  • -
  • pygame.mouse.get_focused() -> bool
  • - state of mouse input focus


    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.


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

    Returns the current position of the mouse cursor. This is the absolute mouse position on the screen.


    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.


    get_pressed() -> (button1, button2, button3)

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


    pygame.mouse.set_visible(bool) -> bool

    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.


    pygame.mouse.get_focused() -> bool

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