Главная страница | назад





Article #27329: How to retrieve the position of the cursor.

QUESTION:

How can I get the current coordinates of the mouse?

ANSWER:

The windows unit provides a wrapper around the Windows API function, GetCursorPos. Passing a TPoint into the function will retrieve the coordinates of the cursor. The following code illustrates how to get the values of the coordinates of the cursor from a button click.

procedure Form1.Button1Click(Sender: TObject);
var
foo: TPoint;
begin
GetCursorPos(foo)
ShowMessage( '(' + IntToStr(foo.X) + ' ,' + IntToStr( foo.Y ) + ')' );
end;

Last Modified: 17-MAY-01