Export (0) Print
Expand All

SetCursorPos function

Moves the cursor to the specified screen coordinates. If the new coordinates are not within the screen rectangle set by the most recent ClipCursor function call, the system automatically adjusts the coordinates so that the cursor stays within the rectangle.

Syntax


BOOL WINAPI SetCursorPos(
  _In_  int X,
  _In_  int Y
);

Parameters

X [in]

Type: int

The new x-coordinate of the cursor, in screen coordinates.

Y [in]

Type: int

The new y-coordinate of the cursor, in screen coordinates.

Return value

Type: BOOL

Returns nonzero if successful or zero otherwise. To get extended error information, call GetLastError.

Remarks

The cursor is a shared resource. A window should move the cursor only when the cursor is in the window's client area.

The calling process must have WINSTA_WRITEATTRIBUTES access to the window station.

The input desktop must be the current desktop when you call SetCursorPos. Call OpenInputDesktop to determine whether the current desktop is the input desktop. If it is not, call SetThreadDesktop with the HDESK returned by OpenInputDesktop to switch to that desktop.

Examples

For an example, see Using the Keyboard to Move the Cursor.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

See also

Reference
ClipCursor
GetCursorPos
SetCaretPos
SetCursor
ShowCursor
Conceptual
Cursors

 

 

Community Additions

ADD
Show:
© 2014 Microsoft