V
victorteng
Unregistered / Unconfirmed
GUEST, unregistred user!
现想计算电脑的空闲时间(计算机空闲5分钟后开始计时),写一DLL使用HOOK键盘和鼠标消息,但如下代码取得的BeginTime和EndTime值总是不对,请大家看看哪里有问题?(以下只以HOOK键盘消息为例)
unit HKProc;
interface
uses
Windows, Messages,Dialogs,SysUtils,DateUtils;
var
hNextHookProc: HHook;
procSaveExit: Pointer;
//
hNextHookProc1: HHook;
procSaveExit1: Pointer;
f:TextFile;
BeginTime:Tdatetime;
EndTime:Tdatetime;
AddTime:longint;
procedure InsertFreeTime(var FreeTime:integer;var BeginTime:String);
function KeyboardHookHandler(iCode: Integer;
wParam: WPARAM;
lParam: LPARAM): LRESULT; stdcall; export;
function EnableHotKeyHook: BOOL; export;
function DisableHotKeyHook: BOOL; export;
procedure HotKeyHookExit; far;
function MouseHookHandler(iCode: Integer;
wParam: WPARAM;
lParam: LPARAM): LRESULT; stdcall; export;
function EnableMouseHook: BOOL; export;
function DisableMouseHook: BOOL; export;
procedure MouseHookExit; far;
implementation
function KeyboardHookHandler(iCode: Integer;
wParam: WPARAM;
lParam: LPARAM): LRESULT; stdcall; export;
const
_KeyPressMask = $80000000;
begin
Result := 0;
If iCode < 0 Then
begin
Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);
Exit;
end;
EndTime:=now;
if SecondsBetween(EndTime,BeginTime)>300 then
begin
AssignFile(f, 'C:/abc.txt');
Append(f);
writeln(f,datetimetostr(BeginTime)+' mouse '+datetimetostr(EndTime));
flush(f);
close(f);
end;
BeginTime:=EndTime;
end;