Home > Language Reference > Windows Management Functions > CursorX

CursorX

The CursorX, CursorY functions return the X, Y coordinates of the text caret (text cursor) of the foreground window.

Usage

Used to acquire dynamically a cursor position.

Syntax

x=CursorX()
    y=CursorY()

Parameters

None.

Return value

x, integer, abscissa in pixels of the text caret relative to the topleft point of the foreground window.

y, integer, ordinate in pixels of the text caret relative to the topleft point of the foreground window.

If no text caret is displayed or if there is no foreground window, the return value is 0.

Example

'Launch notepad
Shell("notepad",1)
'Type Hello in the notepad window
UseWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
 SendKeys("Hello")
'Retrieve the caret position when the cursor is just after the o of Hello
'str$ function is used to convert the integer returned by cursorx/cursory into a string which is then displayed using msgbox
 msgbox(str$(cursorx()))
 msgbox(str$(cursory()))