unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; procedure FormCreate(Sender: TObject); 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; EventLog:Integer; PlayLog:Integer; hHook,hPlay:Integer; bDelay:Bool;implementation{$R *.DFM} Function PlayProc(iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall; begin 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 (iCode=HC_GETNEXT) then begin if bDelay then begin bDelay:=False; Result:=50; end; pEventMSG(lParam)^:=EventArr[PlayLog]; end else if (iCode = HC_SKIP)then begin bDelay := True; PlayLog:=PlayLog+1; end; if PlayLog>=EventLog then begin UNHookWindowsHookEx(hPlay); end; end;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 (iCode = HC_ACTION) then begin EventArr[EventLog]:=pEventMSG(lParam)^; EventLog:=EventLog+1; if EventLog>=1000 then begin UnHookWindowsHookEx(hHook); end; end; end;procedure TForm1.FormCreate(Sender: TObject); begin Button2.Enabled:=False; Button3.Enabled:=False; end;procedure TForm1.Button1Click(Sender: TObject); begin EventLog:=0; hHook:=SetwindowsHookEx(WH_JOURNALRECORD,HookProc,HInstance,0); Button2.Enabled:=True; Button1.Enabled:=False; Button3.Enabled:=False; end;procedure TForm1.Button3Click(Sender: TObject); begin PlayLog:=0; hPlay:=SetwindowsHookEx(WH_JOURNALPLAYBACK,PlayProc, HInstance,0); end; procedure TForm1.Button2Click(Sender: TObject); begin UnHookWindowsHookEx(hHook); hHook:=0; Button1.Enabled:=True; Button2.Enabled:=False; Button3.Enabled:=True; end;end.就是这个了,你看看:)整个工程文件我已经给你发到邮箱里了
方便的话,可以发我邮箱也行。[email protected]
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure FormCreate(Sender: TObject);
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;
EventLog:Integer;
PlayLog:Integer;
hHook,hPlay:Integer;
bDelay:Bool;implementation{$R *.DFM}
Function PlayProc(iCode:Integer;wParam:wParam;lParam:lParam):LRESULT;stdcall;
begin
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 (iCode=HC_GETNEXT) then begin
if bDelay then begin
bDelay:=False;
Result:=50;
end;
pEventMSG(lParam)^:=EventArr[PlayLog];
end
else if (iCode = HC_SKIP)then begin
bDelay := True;
PlayLog:=PlayLog+1;
end;
if PlayLog>=EventLog then begin
UNHookWindowsHookEx(hPlay);
end;
end;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 (iCode = HC_ACTION) then begin
EventArr[EventLog]:=pEventMSG(lParam)^;
EventLog:=EventLog+1; if EventLog>=1000 then begin
UnHookWindowsHookEx(hHook);
end;
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Button2.Enabled:=False;
Button3.Enabled:=False;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
EventLog:=0;
hHook:=SetwindowsHookEx(WH_JOURNALRECORD,HookProc,HInstance,0);
Button2.Enabled:=True;
Button1.Enabled:=False;
Button3.Enabled:=False;
end;procedure TForm1.Button3Click(Sender: TObject);
begin
PlayLog:=0;
hPlay:=SetwindowsHookEx(WH_JOURNALPLAYBACK,PlayProc,
HInstance,0);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
UnHookWindowsHookEx(hHook);
hHook:=0;
Button1.Enabled:=True;
Button2.Enabled:=False;
Button3.Enabled:=True;
end;end.就是这个了,你看看:)整个工程文件我已经给你发到邮箱里了