?? unitfrmmain.~pas
字號(hào):
unit unitFrmMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
EventArr: array[0..1000] of EVENTMSG; //用于保存消息的數(shù)組
EventLog: Integer;
PlayLog: Integer;
hHook, hPlay: Integer;
recOK: Integer;
canPlay: Integer;
bDelay: Bool;
S:STRING;
implementation
{$R *.DFM}
// PlayProc是消息回放函數(shù),當(dāng)系統(tǒng)可以執(zhí)行消息回放
//時(shí)調(diào)用該函數(shù),程序就將先前記錄的消息值返回到lParam指向的區(qū)域中,
//系統(tǒng)就會(huì)執(zhí)行該消息,從而實(shí)現(xiàn)了消息回放。
function PlayProc(iCode: Integer; wParam: wParam; lParam: lParam): LRESULT; stdcall;
begin
canPlay := 1;
Result := 0;
if iCode < 0 then //必須將消息傳遞到消息鏈的下一個(gè)接收單元
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是記錄操作的消息函數(shù),每當(dāng)有鼠標(biāo)鍵盤(pán)消息發(fā)生時(shí),系統(tǒng)都會(huì)調(diào)用該函數(shù),消息信
//息就保存在地址lParam中,我們可以把消息保存在一個(gè)數(shù)組中。
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;
//點(diǎn)擊記錄按鈕開(kāi)始錄像操作
procedure TForm1.Button1Click(Sender: TObject);
begin
S:=EDIT1.TEXT;
EventLog := 0;
//建立鍵盤(pán)鼠標(biāo)操作消息紀(jì)錄鏈
hHook := SetwindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, 0);
Button2.Enabled := True;
Button1.Enabled := False;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
UnHookWindowsHookEx(hHook);
hHook := 0;
ShowMessage('記錄成功');
Button1.Enabled := True;
Button2.Enabled := False;
Button3.Enabled := True;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
EDIT1.Text:=S;
PlayLog := 0;
//建立鍵盤(pán)鼠標(biāo)操作消息紀(jì)錄回放鏈
hPlay := SetwindowsHookEx(WH_JOURNALPLAYBACK, PlayProc,
HInstance, 0);
Button3.Enabled := False;
end;
end.
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -