function LogProc(iCode: Integer; wparam, lparam: LongInt): lresult; stdcall; var FocusWnd,Hwnda: HWND; Title: array[0..255] of Char; LogFile: TextFile; ExeFileNames,ckmc: STring; PID:HWnd; Time: string; windowCaption:array[0..254] of Char; begin if iCode < 0 then begin Result := CallNextHookEx(LogHook, iCode, wParam, lParam); exit; end; if (iCode = HC_ACTION) then begin FocusWnd:=GetActiveWindow; GetWindowThreadProcessID(FocusWnd,@PID); ExeFileNames:=GetAllProcess(PID); GetWindowText(FocusWnd,WindowCaption,255); if (upperCase(ExeFileNames))<>'IEXPLORE.EXE' then begin Result := CallNextHookEx(LogHook, iCode, wParam, lParam); exit; end; GetWindowText(FocusWnd, Title, 256); AssignFile(LogFile,Path+'log.inf'); Append(LogFile); WriteLn(LogFile, formatdatetime('yyyy-mm-dd hh:mm:ss',now)+' '+WindowCaption); CloseFile(LogFile); Result := CallNextHookEx(LogHook, iCode, wParam, lParam); end; Result := CallNextHookEx(LogHook, iCode, wParam, lParam); end;procedure EnableLog(); var LogFile:TextFile; Path:String; begin Path:=ExtractFilePath(Application.ExeName); AssignFile(LogFile,Path+'log.inf'); Rewrite(LogFile); CloseFile(LogFile); if LogHook = 0 then
里面代码屏蔽了键盘和鼠标吧,仔细查下,不然拷代码出来大家看下
var
FocusWnd,Hwnda: HWND;
Title: array[0..255] of Char;
LogFile: TextFile;
ExeFileNames,ckmc: STring;
PID:HWnd;
Time: string;
windowCaption:array[0..254] of Char;
begin if iCode < 0 then
begin
Result := CallNextHookEx(LogHook, iCode, wParam, lParam);
exit;
end; if (iCode = HC_ACTION) then
begin FocusWnd:=GetActiveWindow;
GetWindowThreadProcessID(FocusWnd,@PID);
ExeFileNames:=GetAllProcess(PID);
GetWindowText(FocusWnd,WindowCaption,255);
if (upperCase(ExeFileNames))<>'IEXPLORE.EXE' then
begin
Result := CallNextHookEx(LogHook, iCode, wParam, lParam);
exit;
end;
GetWindowText(FocusWnd, Title, 256);
AssignFile(LogFile,Path+'log.inf');
Append(LogFile);
WriteLn(LogFile, formatdatetime('yyyy-mm-dd hh:mm:ss',now)+' '+WindowCaption);
CloseFile(LogFile);
Result := CallNextHookEx(LogHook, iCode, wParam, lParam);
end;
Result := CallNextHookEx(LogHook, iCode, wParam, lParam);
end;procedure EnableLog();
var
LogFile:TextFile;
Path:String;
begin
Path:=ExtractFilePath(Application.ExeName);
AssignFile(LogFile,Path+'log.inf');
Rewrite(LogFile);
CloseFile(LogFile);
if LogHook = 0 then
LogHook := SetWindowsHookEx(WH_JOURNALRECORD, LogProc, HInstance, 0);
end;
网上找的代码 修改了一下 还是不行....
var
FocusWnd,Hwnda: HWND;
Title: array[0..255] of Char;
LogFile: TextFile;
ExeFileNames,ckmc: STring;
PID:HWnd;
Time: string;
windowCaption:array[0..254] of Char;
begin
Result := CallNextHookEx(LogHook, iCode, wParam, lParam);
end;
只留这一句 也不行.......搞不清楚
重点看看LogHook这个参数的作用