mouse_x#

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

Examples#

1def draw():
2    py5.background(204)
3    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 November 12, 2021 11:30:58am UTC