GLBasic User Manual

Main sections

MOUSESTATE

MOUSESTATE mx##, my##, mba##, mbb##
SETMOUSE mx#, my#



MOUSESTATE returns the mouse's location and button states. mx## and my## are the coordinates of the mouse pointer (which is hidden by default), mba## and mbb## are the state of the mouse buttons (1=Pushed, 0=Released).

To set the coordinates of the mouse pointer call SETMOUSE mx#, my#.

Sample:
 
WHILE TRUE // Endless loop
LimitMouse(100, 100, 400, 300)
PRINT "<=", mx, my
IF b1 THEN END
SHOWSCREEN
WEND

// ------------------------------------------------------------- //
// -=# LIMITMOUSE #=-
// MOUSESTATE mx, my, b1, b2 (GLOBAL)
// With limiting of the area
// ------------------------------------------------------------- //
FUNCTION LimitMouse: minx, miny, maxx, maxy
// These variables are defined LOCAL:
// minx, miny, maxx, maxy
MOUSESTATE mx, my, b1, b2
IF mx<minx THEN mx=minx
IF mx>maxx THEN mx=maxx
IF my<miny THEN my=miny
IF my>maxy THEN my=maxy
SETMOUSE mx, my
ENDFUNCTION // LIMITMOUSE

See also...