[DllImport("kernel32.dll",SetLastError=true)]
static extern uint GetTickCount();
[DllImport("user32.dll",SetLastError=true)]
static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
[StructLayout( LayoutKind.Sequential )]
struct LASTINPUTINFO
{
public static readonly int SizeOf = Marshal.SizeOf(typeof(LASTINPUTINFO));
[MarshalAs(UnmanagedType.U4)]
public int cbSize;
[MarshalAs(UnmanagedType.U4)]
public uint dwTime;
}
public static bool IsInputIdle(int idleTimeoutSecond)
{
LASTINPUTINFO LInInfo;
LInInfo.cbSize = LASTINPUTINFO.SizeOf();
if (GetLastInputInfo(ref LInInfo) != 0)
{
return (GetTickCount() - LInInfo.dwTime) > idleTimeoutSecond;
}
else
return false;
}