I have been using this for long time but now I have found the bug that after 48 days it dos not give me the right idle time.
It is due to the integer32 bits. I could manage to get the tick counter in long through Environment.TickCount is not enough
However, my need is to get the idletime and GetLastInputTime() [http://www.codeproject.com/KB/system/rtwidledll.aspx?display=PrintAll] is not returning me long.
public static int GetIdleTime()
{
return (Environment.TickCount & Int32.MaxValue)- (int)GetLastInputTime();
}
/// <summary>
/// Get the last input time from the input devices.
/// Exception:
/// If it cannot get the last input information then it throws an exception with
/// the appropriate message.
/// </summary>
/// <returns>Last input time in milliseconds.</returns>
public static uint GetLastInputTime()
{
LastInputInfo lastInPut = new LastInputInfo();
lastInPut.BlockSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(lastInPut);
if (!GetLastInputInfo(ref lastInPut))
{
throw new Exception(GetLastError().ToString());
}
return lastInPut.Time;
}