Help / WLanguage / WLanguage functions / Standard functions / Windows management functions / Mouse functions
  • Calculating the mouse position
  • Miscellaneous
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WindowsLinuxPHPWEBDEV - Browser code
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Stored procedures
Returns and modifies the position of the mouse cursor.
Remark: To know the current position of the mouse, it is advisable to use the functions MouseXPos and MouseYPos.
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>)
<Result>: Integer
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:
cpClientMouse position in relation to the client area of the window with focus.
Client Area = window without title bar, menu bar and border.
(Default value)
Position of the mouse in relation to the screen.
cpWindowPosition 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 and LoWord.
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.
Component: wd270std.dll
Minimum version required
  • Version 9
This page is also available for…
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help