Guest User

Untitled

a guest
Jul 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.ComponentModel;
  4.  
  5. namespace GetLastUserInput
  6. {
  7. public class GetLastUserInput
  8. {
  9. private struct LASTINPUTINFO
  10. {
  11. public uint cbSize;
  12. public uint dwTime;
  13. }
  14. private static LASTINPUTINFO lastInPutNfo;
  15. static GetLastUserInput()
  16. {
  17. lastInPutNfo = new LASTINPUTINFO();
  18. lastInPutNfo.cbSize = (uint)Marshal.SizeOf(lastInPutNfo);
  19. }
  20. [DllImport("User32.dll")]
  21. private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
  22.  
  23. /// <summary>
  24. /// Idle time in ticks
  25. /// </summary>
  26. /// <returns></returns>
  27. public static uint GetIdleTickCount()
  28. {
  29. return ((uint)Environment.TickCount - GetLastInputTime());
  30. }
  31. /// <summary>
  32. /// Last input time in ticks
  33. /// </summary>
  34. /// <returns></returns>
  35. public static uint GetLastInputTime()
  36. {
  37. if (!GetLastInputInfo(ref lastInPutNfo))
  38. {
  39. throw new Win32Exception(Marshal.GetLastWin32Error());
  40. }
  41. return lastInPutNfo.dwTime;
  42. }
  43. }
  44. }
Add Comment
Please, Sign In to add comment