mouse_x

mouse_x#

The system variable mouse_x always contains the current horizontal coordinate of the mouse.

Examples#

def draw():
    py5.background(204)
    py5.line(py5.mouse_x, 20, py5.mouse_x, 80)

Description#

The system variable mouse_x always contains the current horizontal coordinate of the mouse.

Note that py5 can only track the mouse position when the pointer is over the current window. The default value of mouse_x is 0, so 0 will be returned until the mouse moves in front of the Sketch window. (This typically happens when a Sketch is first run.) Once the mouse moves away from the window, mouse_x will continue to report its most recent position.

Underlying Processing field: mouseX

Updated on March 06, 2023 02:49:26am UTC