像屏保判断键盘鼠标是否移动 时间的不准确性?该怎么处理
像屏保判断键盘鼠标是否移动 时间的不准确性????急。。。。。
问题:
计时器把inc(Timesnum);的时候,Timesnum 常常复位到1。比如已经Timesnum 已经=89了,但是应该是=90的时候,变成了 1。我是用 label1.Caption := IntToStr(Timesnum);来显示的。请各位大侠出手。
代码如下:
var
Form1: TForm1;
hHook: integer;
Timesnum: integer;
const
Timescount = 300*4;
function HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;
begin
Timesnum := 0;
Result := 0;
end;
function StartHook: Boolean;
begin
Result := False;
if hHook = 0 then
begin
hHook := SetWindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, 0);
if hHook > 0 then
begin
Result := True;
end;
end;
end;
procedure StopHook;
begin
if hHOok > 0 then
begin
UnHookWindowsHookEx(hHook);
hHook := 0;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
hHook := 0;
StartHook();
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
stophook;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
inc(Timesnum);
label1.Caption := IntToStr(Timesnum);
if Timesnum > Timescount then
ShowMessage( '已经好久没动键盘和鼠标了! ');
end;
------解决方案--------------------
帮顶!~
------解决方案--------------------
要复位可以这样写写在:
HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;
begin
if 鼠标或者键盘动作 then
Timesnum := 0;
Result := 0;
end;
function StartHook: Boolean;
begin
Result := False;
if hHook = 0 then
begin
Timesnum := 0; // 在这里初始化
hHook := SetWindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, 0);
if hHook > 0 then
begin
Result := True;
end;
end;
end;
问题:
计时器把inc(Timesnum);的时候,Timesnum 常常复位到1。比如已经Timesnum 已经=89了,但是应该是=90的时候,变成了 1。我是用 label1.Caption := IntToStr(Timesnum);来显示的。请各位大侠出手。
代码如下:
var
Form1: TForm1;
hHook: integer;
Timesnum: integer;
const
Timescount = 300*4;
function HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;
begin
Timesnum := 0;
Result := 0;
end;
function StartHook: Boolean;
begin
Result := False;
if hHook = 0 then
begin
hHook := SetWindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, 0);
if hHook > 0 then
begin
Result := True;
end;
end;
end;
procedure StopHook;
begin
if hHOok > 0 then
begin
UnHookWindowsHookEx(hHook);
hHook := 0;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
hHook := 0;
StartHook();
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
stophook;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
inc(Timesnum);
label1.Caption := IntToStr(Timesnum);
if Timesnum > Timescount then
ShowMessage( '已经好久没动键盘和鼠标了! ');
end;
------解决方案--------------------
帮顶!~
------解决方案--------------------
要复位可以这样写写在:
HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;
begin
if 鼠标或者键盘动作 then
Timesnum := 0;
Result := 0;
end;
function StartHook: Boolean;
begin
Result := False;
if hHook = 0 then
begin
Timesnum := 0; // 在这里初始化
hHook := SetWindowsHookEx(WH_JOURNALRECORD, HookProc, HInstance, 0);
if hHook > 0 then
begin
Result := True;
end;
end;
end;