作者在 2010-08-01 09:12:18 发布以下内容
unit Mouse_Event_Demo;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
ioriliao1: TMenuItem;
QQ825306621: TMenuItem;
N2010811: TMenuItem;
Button4: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{模拟鼠标动作API函数mouse_event,它可以实现模拟鼠标按下和放开等动作。}
{procedure mouse_event(dwFlags, dx, dy, dwData, dwExtraInfo: DWORD); stdcall;}
{参数说明:}
{dwFlags, 鼠标动作标识。}
{dx, 鼠标水平方向位置。 }
{dy, 鼠标垂直方向位置。 }
{dwData, 鼠标轮子转动的数量。}
{dwExtraInfo,一个关联鼠标动作辅加信息。}
{其中,dwFlags表示了各种各样的鼠标动作和点击活动,它的常用取值如下:}
{MOUSEEVENTF_MOVE 表示模拟鼠标移动事件。}
{MOUSEEVENTF_LEFTDOWN 表示模拟按下鼠标左键。}
{MOUSEEVENTF_LEFTUP 表示模拟放开鼠标左键。}
{MOUSEEVENTF_RIGHTDOWN 表示模拟按下鼠标右键。}
{MOUSEEVENTF_RIGHTUP 表示模拟放开鼠标右键。}
{MOUSEEVENTF_MIDDLEDOWN 表示模拟按下鼠标中键。}
{MOUSEEVENTF_MIDDLEUP 表示模拟放开鼠标中键。}
{获取当前鼠标位置函数GetCursorPos()}
{function GetCursorPos(var lpPoint: TPoint): BOOL; stdcall;}
{参数说明:}
{lpPoint, 返回鼠标的当前位置。}
{TPoint结构说明:}
{TPoint = packed record
X: Longint; 鼠标的水平方向位置。
Y: Longint; 鼠标的垂直方向位置。
end;}
{返回值:如果成功,返回True;如果失败,返回值为False。}
{设置当前鼠标位置函数SetCursorPos()。}
{function SetCursorPos(X, Y: Integer): BOOL; stdcall;}
{参数说明:}
{X, 鼠标的水平方向位置。}
{Y, 鼠标的垂直方向位置。}
{返回值:如果成功,返回True;如果失败,返回值为False。}
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
{模拟鼠标相对当前位置水平移动50个像素}
procedure TForm1.Button1Click(Sender: TObject);begin
Mouse_Event(MOUSEEVENTF_MOVE,50,0,0,0);
end;
{模拟鼠标左键单击}
procedure TForm1.Button2Click(Sender: TObject);begin
{先把鼠标移动到目标按钮}
Mouse_Event(MOUSEEVENTF_MOVE,30,0,0,0);
{模拟鼠标左键按下动作}
Mouse_Event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
{模拟鼠标左键弹起动作}
Mouse_Event(MOUSEEVENTF_LEFTUP,0,0,0,0);
end;
procedure TForm1.Button3Click(Sender: TObject);begin
ShowMessage('鼠标左键已经单击中了我');
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
{先把鼠标移动到目标窗体}
Mouse_Event(MOUSEEVENTF_MOVE,0,50,0,0);
{模拟鼠标右键按下动作}
Mouse_Event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
{模拟鼠标右键弹起动作}
Mouse_Event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
ioriliao1: TMenuItem;
QQ825306621: TMenuItem;
N2010811: TMenuItem;
Button4: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{模拟鼠标动作API函数mouse_event,它可以实现模拟鼠标按下和放开等动作。}
{procedure mouse_event(dwFlags, dx, dy, dwData, dwExtraInfo: DWORD); stdcall;}
{参数说明:}
{dwFlags, 鼠标动作标识。}
{dx, 鼠标水平方向位置。 }
{dy, 鼠标垂直方向位置。 }
{dwData, 鼠标轮子转动的数量。}
{dwExtraInfo,一个关联鼠标动作辅加信息。}
{其中,dwFlags表示了各种各样的鼠标动作和点击活动,它的常用取值如下:}
{MOUSEEVENTF_MOVE 表示模拟鼠标移动事件。}
{MOUSEEVENTF_LEFTDOWN 表示模拟按下鼠标左键。}
{MOUSEEVENTF_LEFTUP 表示模拟放开鼠标左键。}
{MOUSEEVENTF_RIGHTDOWN 表示模拟按下鼠标右键。}
{MOUSEEVENTF_RIGHTUP 表示模拟放开鼠标右键。}
{MOUSEEVENTF_MIDDLEDOWN 表示模拟按下鼠标中键。}
{MOUSEEVENTF_MIDDLEUP 表示模拟放开鼠标中键。}
{获取当前鼠标位置函数GetCursorPos()}
{function GetCursorPos(var lpPoint: TPoint): BOOL; stdcall;}
{参数说明:}
{lpPoint, 返回鼠标的当前位置。}
{TPoint结构说明:}
{TPoint = packed record
X: Longint; 鼠标的水平方向位置。
Y: Longint; 鼠标的垂直方向位置。
end;}
{返回值:如果成功,返回True;如果失败,返回值为False。}
{设置当前鼠标位置函数SetCursorPos()。}
{function SetCursorPos(X, Y: Integer): BOOL; stdcall;}
{参数说明:}
{X, 鼠标的水平方向位置。}
{Y, 鼠标的垂直方向位置。}
{返回值:如果成功,返回True;如果失败,返回值为False。}
procedure TForm1.FormCreate(Sender: TObject);
begin
end;
{模拟鼠标相对当前位置水平移动50个像素}
procedure TForm1.Button1Click(Sender: TObject);begin
Mouse_Event(MOUSEEVENTF_MOVE,50,0,0,0);
end;
{模拟鼠标左键单击}
procedure TForm1.Button2Click(Sender: TObject);begin
{先把鼠标移动到目标按钮}
Mouse_Event(MOUSEEVENTF_MOVE,30,0,0,0);
{模拟鼠标左键按下动作}
Mouse_Event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
{模拟鼠标左键弹起动作}
Mouse_Event(MOUSEEVENTF_LEFTUP,0,0,0,0);
end;
procedure TForm1.Button3Click(Sender: TObject);begin
ShowMessage('鼠标左键已经单击中了我');
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
{先把鼠标移动到目标窗体}
Mouse_Event(MOUSEEVENTF_MOVE,0,50,0,0);
{模拟鼠标右键按下动作}
Mouse_Event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
{模拟鼠标右键弹起动作}
Mouse_Event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
end;
end.