Skip to content

use_mouse

API

counterweight.hooks.use_mouse

use_mouse() -> Mouse
RETURNS DESCRIPTION
Mouse

A record describing the current state of the mouse.

counterweight.hooks.Mouse dataclass

Mouse(
    absolute: Position, motion: Position, button: int | None
)

absolute instance-attribute

absolute: Position

The absolute position of the mouse on the screen (i.e., the top-left corner of the screen is Position(x=0, y=0)).

motion instance-attribute

motion: Position

The difference in the absolute position of the mouse since the last render cycle.

button instance-attribute

button: int | None

The button that is currently pressed, or None if no button is pressed.

use_mouse vs. on_mouse

use_mouse and on_mouse provide similar functionality, but use_mouse is a hook and on_mouse is an event handler. use_mouse is more efficient when a component depends only on the current state of the mouse (e.g., the current position, or whether a button is currently pressed), while on_mouse is more convenient when a component needs to respond to changes in the mouse state, (e.g., a button release (MouseUp).