O
okgxsh
Unregistered / Unconfirmed
GUEST, unregistred user!
delphi开发触摸屏时,如何检测多久没有进行屏幕操作了???(全部家当)
我从网上找了一段代码,它只能检测键盘多久没有进行操作了,却检测不了鼠标!
//代码如下 ===========那位大哥帮帮忙阿
unit ETimer;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TETimer = class(TTimer)
private
function GetSnooze: Longint;
procedure SetSnooze(const Value: Longint);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
property Snooze:Longint read GetSnooze write SetSnooze;
published
{ Published declarations }
end;
procedure Register;
implementation
var
Instances:integer;
ElapsedTime:Longint;
whKeyBoard,whMouse:HHook;
procedure Register;
begin
RegisterComponents('System', [TETimer]);
end;
{ TIdleTimer }
function MouseHookCallBack(Code:integer;Msg:lParam;MouseHook:wParam)WORD;stdcall;
begin
if Code>=0 then ElapsedTime :=GetTickCount;
Result := CallNextHookEx(whMouse,Code,Msg,MouseHook);
end;
function KeyBoardCallBack(Code:integer;Msg:word;KeyBoardHook:Longint):LongInt;stdcall;
begin
if Code>=0 then ElapsedTime :=GetTickCount;
Result := CallNextHookEx(whKeyBoard,Code,Msg,KeyBoardHook);
end;
constructor TETimer.Create(AOwner: TComponent);
function GetModuleHandleFromInstance:THandle;
var
s:array[0..512] of char;
begin
GetModuleFileName(HInstance,s,SizeOf(s)-1);
Result :=GetModuleHandle(s);
end;
begin
inherited Create(AOwner);
Inc(Instances);
if Instances =1 then begin
ElapsedTime :=GetTickCount;
whMouse := SetWindowsHookEx(WH_MOUSE,@MouseHookCallback,GetModuleHandleFromInstance,0);
whKeyBoard :=SetWindowsHookEx(WH_KEYBOARD,@KeyBoardCallBack,GetModuleHandleFromInstance,0);
end;
end;
destructor TETimer.Destroy;
begin
Dec(Instances);
if Instances =0 then begin
UnhookWindowsHookEx(whKeyBoard);
UnhookWindowsHookEx(whMouse);
end;
inherited;
end;
function TETimer.GetSnooze: Longint;
begin
Result:= GetTickCount - ElapsedTime;
end;
procedure TETimer.SetSnooze(const Value: Longint);
begin
ElapsedTime := GetTickCount + Value;
end;
end.
我从网上找了一段代码,它只能检测键盘多久没有进行操作了,却检测不了鼠标!
//代码如下 ===========那位大哥帮帮忙阿
unit ETimer;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TETimer = class(TTimer)
private
function GetSnooze: Longint;
procedure SetSnooze(const Value: Longint);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
property Snooze:Longint read GetSnooze write SetSnooze;
published
{ Published declarations }
end;
procedure Register;
implementation
var
Instances:integer;
ElapsedTime:Longint;
whKeyBoard,whMouse:HHook;
procedure Register;
begin
RegisterComponents('System', [TETimer]);
end;
{ TIdleTimer }
function MouseHookCallBack(Code:integer;Msg:lParam;MouseHook:wParam)WORD;stdcall;
begin
if Code>=0 then ElapsedTime :=GetTickCount;
Result := CallNextHookEx(whMouse,Code,Msg,MouseHook);
end;
function KeyBoardCallBack(Code:integer;Msg:word;KeyBoardHook:Longint):LongInt;stdcall;
begin
if Code>=0 then ElapsedTime :=GetTickCount;
Result := CallNextHookEx(whKeyBoard,Code,Msg,KeyBoardHook);
end;
constructor TETimer.Create(AOwner: TComponent);
function GetModuleHandleFromInstance:THandle;
var
s:array[0..512] of char;
begin
GetModuleFileName(HInstance,s,SizeOf(s)-1);
Result :=GetModuleHandle(s);
end;
begin
inherited Create(AOwner);
Inc(Instances);
if Instances =1 then begin
ElapsedTime :=GetTickCount;
whMouse := SetWindowsHookEx(WH_MOUSE,@MouseHookCallback,GetModuleHandleFromInstance,0);
whKeyBoard :=SetWindowsHookEx(WH_KEYBOARD,@KeyBoardCallBack,GetModuleHandleFromInstance,0);
end;
end;
destructor TETimer.Destroy;
begin
Dec(Instances);
if Instances =0 then begin
UnhookWindowsHookEx(whKeyBoard);
UnhookWindowsHookEx(whMouse);
end;
inherited;
end;
function TETimer.GetSnooze: Longint;
begin
Result:= GetTickCount - ElapsedTime;
end;
procedure TETimer.SetSnooze(const Value: Longint);
begin
ElapsedTime := GetTickCount + Value;
end;
end.