Simulate mouse moves and clicks

You can move mouse cursor and simulate clicking programmatically using just one simple procedure.

In code below is one simple example to activate Start menu. Mouse cursor is moved to left-bottom corner of screen and then the left mouse button is “pressed and released”. Of course, this example will work only if you have “standard” Start menu position (bottom of screen), but example just shows the principle.

procedure TForm1.Button1Click(Sender: TObject);
begin
  SetCursorPos(20, Screen.Height-20); //set cursor to Start menu coordinates
  mouse_event(MOUSEEVENTF_LEFTDOWN,0, 0, 0, 0); //press left button
  mouse_event(MOUSEEVENTF_LEFTUP,0, 0, 0, 0); //release left button
end;

To simulate right button, use MOUSEEVENTF_RIGHTDOWN and MOUSEEVENTF_RIGHTUP parameters.

Leave a Reply