/// <summary> /// Returns time since last user action, i.e. how long they've been idle /// </summary> /// <returns>User idle time in miliseconds</returns> public static uint GetIdleTime() { var lastInPut = new LASTINPUTINFO(); lastInPut.cbSize = (uint)Marshal.SizeOf(lastInPut); GetLastInputInfo(ref lastInPut); return (uint)Environment.TickCount - lastInPut.dwTime; }
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);