delphi开发触摸屏时,如何检测多久没有进行屏幕操作了???(全部家当) ( 积分: 40 )

  • 主题发起人 主题发起人 okgxsh
  • 开始时间 开始时间
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):DWORD;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.
 
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):DWORD;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.
 
贴段代码,自己研究
//-------钩子回调函数---(有消息时候该函数将被调用)-----------------

function JournalHookProc(iCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
Result := CallNextHookEx(frmMain.nextHook, iCode, wParam, lParam);
//键盘消息
if ((PEventMsg(lparam)^.message >= WM_KEYFIRST) and
(PEventMsg(lparam)^.message <= WM_KEYLAST)) or
//鼠标消息
((PEventMsg(lparam)^.message >= WM_MOUSEFIRST) and
(PEventMsg(lparam)^.message <= WM_MOUSELAST)) then
begin
//如果现在的时间-最后活动时间>=2个小时,认为用户离开电脑以后又回来了
if (Time - frmMain.lastActiveTime >= StrToTime('02:00:00')) then
begin
frmMain.lastActiveTime := Time;
frmMain.MsnPopToday;
end
else
frmMain.lastActiveTime := Time;
end;
end;
 
你的触摸屏是串口的吗?如果是就用spcomm控件就能实现呀
 
这个你也看看吧
系统空闲时间检测 Idle
我们知道,当用户超过一定的时间没有输入之后,Windows就会启动屏幕保护功能,那么在程序中如何做到这一点呢?就是说我如何检测到用户多久没有输入呢?大家知道,在Windows中有一个Hook技术,就是钩子,我们利用Hook技术,Hook键盘和鼠标,这样就可以知道用户有没有输入了!因此,我们可以修改Timer控件,继承下来就可以了:
用法:
if IdleTimer1.Snooze>6000 then
ShowMessage('用户已经有6秒钟没有输入了!');
///FileName:IdleTimer.Pas
unit IdleTimer;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;

type
TIdleTimer = 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', [TIdleTimer]);
end;

{ TIdleTimer }

function MouseHookCallBack(Code:integer;Msg:lParam;MouseHook:wParam):DWORD;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 TIdleTimer.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 TIdleTimer.Destroy;
begin
Dec(Instances);
if Instances =0 then begin
UnhookWindowsHookEx(whKeyBoard);
UnhookWindowsHookEx(whMouse);
end;
inherited;
end;

function TIdleTimer.GetSnooze: Longint;
begin
Result:= GetTickCount - ElapsedTime;
end;

procedure TIdleTimer.SetSnooze(const Value: Longint);
begin
ElapsedTime := GetTickCount + Value;
end;

end.
 
对,同意楼上的方法,不过他的代码没有看,呵呵,如果需要代码问我要,我的EM:ljj_laoniu@hotmail.com
 
简单问题复杂化,实在是不值一提的问题。
 
多人接受答案了。
 
后退
顶部