Delphi Code
[HTML]View PlainCopy
- Unit Unit1;
- Interface
- Uses
- Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
- Dialogs, Stdctrls, Extctrls;
- Type
- TForm1 = Class (Tform)
- Button1:tbutton;
- Timer1:ttimer;
- Procedure Timer1timer (Sender:tobject);
- Private
- {Private declarations}
- Public
- {Public declarations}
- End
- typedef struct TAGLASTINPUTINFO {
- UINT cbsize;
- DWORD Dwtime;
- Lastinputinfo, *plastinputinfo;
- Type
- lastinputinfo = record
- Cbsize:uint;
- Dwtime:dword;
- End
- Var
- Form1:tform1;
- Implementation
- {$R *.DFM}
- function getinputawaytime ():D word;
- Var
- Lpi:tlastinputinfo;
- Begin
- Lpi.cbsize : = sizeof (LPI);
- Getlastinputinfo (LPI);
- Result : = Round ((GetTickCount ()-lpi.dwtime)/1000);
- End
- Procedure Tform1.timer1timer (Sender:tobject);
- Begin
- Caption : = inttostr (getinputawaytime)
- End
- End.
VC Code
[HTML]View PlainCopy
- DWORD Getinputawaytime ()
- {
- Lastinputinfo LPI;
- lpi.cbsize = sizeof (LPI);
- Getlastinputinfo (&LPI);
- Return DWORD ((GetTickCount ()-lpi.dwtime)/1000);
- }
http://blog.csdn.net/cmdasm/article/details/10158601
Detect how long the mouse keyboard is inactive (using Getlastinputinfo API function detection)