自己开发的delphi 100lei 内容丰富 绝对不要错过了啊。
源代码在线查看: unitfrmmain.pas
unit unitFrmMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Edit1: TEdit;
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;
EventArr: array[0..1000] of EVENTMSG; //用于保存消息的数组
EventLog: Integer;
PlayLog: Integer;
hHook, hPlay: Integer;
recOK: Integer;
canPlay: Integer;
bDelay: Bool;
implementation
{$R *.DFM}
// PlayProc是消息回放函数,当系统可以执行消息回放
//时调用该函数,程序就将先前记录的消息值返回到lParam指向的区域中,
//系统就会执行该消息,从而实现了消息回放。
function PlayProc(iCode: Integer; wParam: wParam; lParam: lParam): LRESULT; stdcall;
begin
canPlay := 1;
Result := 0;
if iCode < 0 then //必须将消息传递到消息链的下一个接收单元
Result := CallNextHookEx(hPlay, iCode, wParam, lParam)
else if iCode = HC_SYSMODALON then
canPlay := 0
else if iCode = HC_SYSMODALOFF then
canPlay := 1
else if ((canPlay = 1) and (iCode = HC_GETNEXT)) then begin
if bDelay then begin
bDelay := False;
Result := 50;
end;
pEventMSG(lParam)^ := EventArr[PlayLog];
end
else if ((canPlay = 1) and (iCode = HC_SKIP)) then begin
bDelay := True;
PlayLog := PlayLog + 1;
end;
if PlayLog >= EventLog then begin
UNHookWindowsHookEx(hPlay);
end;
end;
//HookProc是记录操作的消息函数,每当有鼠标键盘消息发生时,系统都会调用该函数,消息信
//息就保存在地址lParam中,我们可以把消息保存在一个数组中。
function HookProc(iCode: Integer; wParam: wParam; lParam: lParam): LRESULT; stdcall;
begin
recOK := 1;
Result := 0;
if iCode < 0 then
Result := CallNextHookEx(hHook, iCode, wParam, lParam)
else if iCode = HC_SYSMODALON then
recOK := 0
else if iCode = HC_SYSMODALOFF then
recOK := 1
else if ((recOK > 0) and (iCode = HC_ACTION)) then begin
EventArr[EventLog] := pEventMSG(lParam)^;
EventLog := EventLog + 1;
if EventLog >= 1000 then begin
UnHookWindowsHookEx(hHook);
end;
end;
end;
//点击记录按钮开始录像操作
procedure TForm1.Button1Click(Sender: TObject);
begin
EventLog := 0;
//建立键盘鼠标操作消息纪录链
hHook := SetwindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, 0);
Button2.Enabled := True;
Button1.Enabled := False;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
UnHookWindowsHookEx(hHook);
hHook := 0;
Button1.Enabled := True;
Button2.Enabled := False;
Button3.Enabled := True;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
PlayLog := 0;
//建立键盘鼠标操作消息纪录回放链
hPlay := SetwindowsHookEx(WH_JOURNALPLAYBACK, PlayProc,
HInstance, 0);
Button3.Enabled := False;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
ShowMessage('it''s recording');
end;
end.