Returns and modifies the position of the mouse cursor.
: To get the position of the mouse cursor, it is recommended to use MouseXPos
Res is int = CursorPos(cpClient)
IF Res <> -1 THEN
Message("Position X = " + LoWord(Res) + "Position Y = " + HiWord(Res))
<Result> = CursorPos([<Marker>, ] <X Position> , <Y Position>)
Position of the mouse (the coordinates are returned by HiWord and LoWord).
- Current position if <X Position> and <Y Position> are not specified.
- Previous position if <X Position> and <Y Position> are specified.
- -1 if an error occurs (position of the mouse outside the requested marker for example).
<Marker>: Optional integer constant
Indicates the marker used to calculate the position:
|cpClient||Mouse position in relation to the client area of the window with focus.|
Client Area = window without title bar, menu bar and border.
|Position of the mouse in relation to the screen.|
|cpWindow||Position of the mouse in relation to the window with focus.|
<X Position>: Real
New horizontal position in the selected marker.
<Y Position>: Real
New vertical position in the selected marker.
Calculating the mouse position
To find out the horizontal and vertical position of the mouse from the result, you must use HiWord
The low byte of <Result> is used to get the horizontal position (X) of the mouse.
The high byte of <Result> is used to get the vertical position (Y) of the mouse. If an error occurs, X and Y are equal to -1.
The coordinates are relative to the top left corner of the selected marker.
- MouseXPos and MouseYPos respectively return the horizontal and vertical positions of the mouse in relation to the control where a left mouse click was performed.
- You can, for example, calculate the position of the mouse cursor in a timer in order to always display this position on the screen.