Detect how long the mouse keyboard is inactive (using Getlastinputinfo API function detection)

Source: Internet
Author: User

Delphi Code

[HTML]View PlainCopy
  1. Unit Unit1;
  2. Interface
  3. Uses
  4. Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, Stdctrls, Extctrls;
  6. Type
  7. TForm1 = Class (Tform)
  8. Button1:tbutton;
  9. Timer1:ttimer;
  10. Procedure Timer1timer (Sender:tobject);
  11. Private
  12. {Private declarations}
  13. Public
  14. {Public declarations}
  15. End
  16. typedef struct TAGLASTINPUTINFO {
  17. UINT cbsize;
  18. DWORD Dwtime;
  19. Lastinputinfo, *plastinputinfo;
  20. Type
  21. lastinputinfo = record
  22. Cbsize:uint;
  23. Dwtime:dword;
  24. End
  25. Var
  26. Form1:tform1;
  27. Implementation
  28. {$R *.DFM}
  29. function getinputawaytime ():D word;
  30. Var
  31. Lpi:tlastinputinfo;
  32. Begin
  33. Lpi.cbsize : = sizeof (LPI);
  34. Getlastinputinfo (LPI);
  35. Result : = Round ((GetTickCount ()-lpi.dwtime)/1000);
  36. End
  37. Procedure Tform1.timer1timer (Sender:tobject);
  38. Begin
  39. Caption : = inttostr (getinputawaytime)
  40. End
  41. End.


VC Code

[HTML]View PlainCopy
      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

Detect how long the mouse keyboard is inactive (using Getlastinputinfo API function detection)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.