码迷,mamicode.com
首页 > Windows程序 > 详细

检测鼠标键盘多久没有活动(使用GetLastInputInfo API函数检测)

时间:2016-08-19 23:55:12      阅读:1725      评论:0      收藏:0      [点我收藏+]

标签:

DELPHI代码

[html] view plain copy
 
  1. unit Unit1;  
  2.   
  3. interface  
  4.   
  5. uses  
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  
  7.   Dialogs, StdCtrls, ExtCtrls;  
  8.   
  9. type  
  10.   TForm1 = class(TForm)  
  11.     Button1: TButton;  
  12.     Timer1: TTimer;  
  13.     procedure Timer1Timer(Sender: TObject);  
  14.   private  
  15.     { Private declarations }  
  16.   public  
  17.     { Public declarations }  
  18.   end;  
  19. //typedef struct tagLASTINPUTINFO {  
  20.   //UINT cbSize;  
  21.  // DWORD dwTime;  
  22. // LASTINPUTINFO, *PLASTINPUTINFO;  
  23.   
  24.   
  25. type  
  26.    LASTINPUTINFO = record  
  27.    cbSize:UINT;  
  28.    dwTime:DWORD;  
  29. end;  
  30. var  
  31.   Form1: TForm1;  
  32.   
  33. implementation  
  34.   
  35. {$R *.dfm}  
  36.   
  37.   
  38.   
  39. function GetInputAwayTime():DWORD;  
  40. var  
  41.   lpi:TLastInputInfo;  
  42. begin  
  43.   lpi.cbSize := sizeof(lpi);  
  44.   GetLastInputInfo(lpi);  
  45.   Result := Round((GetTickCount()-lpi.dwTime)/1000);  
  46. end;  
  47. procedure TForm1.Timer1Timer(Sender: TObject);  
  48. begin  
  49.    Caption := IntToStr(GetInputAwayTime)  
  50. end;  
  51.   
  52. end.  


VC代码

[html] view plain copy
 
    1. DWORD GetInputAwayTime()  
    2. {  
    3.   LASTINPUTINFO lpi;  
    4.   lpi.cbSize = sizeof(lpi);  
    5.   GetLastInputInfo(&lpi);  
    6.   return DWORD((GetTickCount()-lpi.dwTime)/1000);  
    7. }  

 

http://blog.csdn.net/cmdasm/article/details/10158601

检测鼠标键盘多久没有活动(使用GetLastInputInfo API函数检测)

标签:

原文地址:http://www.cnblogs.com/findumars/p/5789402.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!