首先啟動一個新的項目
這
下面以鼠標左鍵單擊為例來說明如何模擬鼠標操作
procedure TForm
begin
SetCursorPos(
mouse_event(MOUSEEVENTF_LEFTDOWN
mouse_event(MOUSEEVENTF_LEFTUP
end;
首先需要通過SetCursorPos函數來設置需要單擊的坐標
雙擊的操作可以通過兩個連續的單擊來實現
程序代碼如下
unit Unit
interface
uses
Windows
Dialogs
type
TForm
btnMove: TButton;
btnLClick: TButton;
btnLDClick: TButton;
btnRClick: TButton;
procedure btnMoveClick(Sender: TObject);
procedure btnLClickClick(Sender: TObject);
procedure btnLDClickClick(Sender: TObject);
procedure btnRClickClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form
implementation
{$R *
procedure TForm
begin
mouse_event(MOUSEEVENTF_MOVE
end;
procedure TForm
begin
SetCursorPos(
mouse_event(MOUSEEVENTF_LEFTDOWN
mouse_event(MOUSEEVENTF_LEFTUP
end;
procedure TForm
begin
SetCursorPos(
mouse_event(MOUSEEVENTF_LEFTDOWN
mouse_event(MOUSEEVENTF_LEFTUP
mouse_event(MOUSEEVENTF_LEFTDOWN
mouse_event(MOUSEEVENTF_LEFTUP
end;
procedure TForm
begin
SetCursorPos(
mouse_event(MOUSEEVENTF_RIGHTDOWN
mouse_event(MOUSEEVENTF_RIGHTUP
end;
end
保存文件
通過單擊窗體上的
本程序介紹了如何在程序中模擬鼠標的常用操作
From:http://tw.wingwit.com/Article/program/Delphi/201311/24687.html