Created
December 1, 2012 00:30
-
-
Save piccaso/4179759 to your computer and use it in GitHub Desktop.
win32 GetLastInputInfo C# example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
using System.ComponentModel; | |
namespace GetLastUserInput | |
{ | |
public class GetLastUserInput | |
{ | |
private struct LASTINPUTINFO | |
{ | |
public uint cbSize; | |
public uint dwTime; | |
} | |
private static LASTINPUTINFO lastInPutNfo; | |
static GetLastUserInput() | |
{ | |
lastInPutNfo = new LASTINPUTINFO(); | |
lastInPutNfo.cbSize = (uint)Marshal.SizeOf(lastInPutNfo); | |
} | |
[DllImport("User32.dll")] | |
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii); | |
/// <summary> | |
/// Idle time in ticks | |
/// </summary> | |
/// <returns></returns> | |
public static uint GetIdleTickCount() | |
{ | |
return ((uint)Environment.TickCount - GetLastInputTime()); | |
} | |
/// <summary> | |
/// Last input time in ticks | |
/// </summary> | |
/// <returns></returns> | |
public static uint GetLastInputTime() | |
{ | |
if (!GetLastInputInfo(ref lastInPutNfo)) | |
{ | |
throw new Win32Exception(Marshal.GetLastWin32Error()); | |
} | |
return lastInPutNfo.dwTime; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LASTINPUTINFO not found. Not connected.