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


    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

  • 相关阅读:
    html 时间区间选择功能
    Django 【settings】数据库设置
    Django forms 定制form字段
    避免js全局变量污染的方法
    js获取路由
    采用遍历的方法获取字符串a在字符串b中的位置
    vue 学习笔记
    Promise
    js常用JSON数据操作
    js 数组遍历方式
  • 原文地址:https://www.cnblogs.com/findumars/p/5789402.html
Copyright © 2020-2023  润新知