MouseX

From Liberty BASIC Family
Jump to navigation Jump to search
Supported in Just BASIC Supported in Liberty BASIC Not supported in Liberty BASIC 5 Not supported in Run BASIC

Description

This special variable, along with MouseY, holds the X, Y coordinates of the mouse position within the client area of a graphic window or graphic-box. The mouse position can only be captured when a graphic window or graphic-box has the input focus. Normally, the mouse position is used when a mouse event occurs. See when mouseEvent

Syntax

  1. MouseX - (case sensitive)

Hints

  • Setting Focus. To be certain your graphic window or graphic-box has the focus, issue a "setfocus" command to the window.
  • Trapping Mouse Position. When a mouse event is trapped, the position of the mouse in X and Y pixel coordinates from the upper left corner of the window or control is placed in the variables MouseX and MouseY. An example:
#handle.ext "setfocus; when mouseMove eventHandler"

Example

An example to retrieve and use mouse coordinates, using both a branch label and a sub for event handlers.

  open "Plot something!" for graphics as #w
  print #w, "when leftButtonMove [paint]"
  print #w, "when leftButtonUp coords"
  print #w, "down ; size 3"
  wait
[paint]
  print #w, "set "; MouseX; " "; MouseY
  wait

sub coords handle$, x, y
    #handle$ "\"; x; " "; y
end sub

Useful Procedures

' Place a useful function or sub using this keyword here