Mega Code Archive

 
Categories / Delphi / VCL
 

Simulating a mouse move in code

Question: Some components do not respond to a cursor change until the user moves the mouse. Is there a way to simulate a mouse move? Answer: The following example shows how to "nudge the mouse" without user intervention. procedure TForm1.Button1Click(Sender: TObject); var pt : TPoint; begin Application.ProcessMessages; Screen.Cursor := CrHourglass; GetCursorPos(pt); SetCursorPos(pt.x + 1, pt.y + 1); Application.ProcessMessages; SetCursorPos(pt.x - 1, pt.y - 1); end;