private bool IsUserActive() { LastInputInfo info = LastInputInfo.Create(); if (!Win32Bindings.GetLastInputInfo(ref info)) { throw new Exception("Could not get time of last user activity"); } long idleTime = Environment.TickCount - info.dwTime; return(idleTime <= Config.TimeToIdle); }
public static Boolean IsUserIdle(Int32 userIdleThresholdInSeconds) { LastInputInfo info = LastInputInfo.Create(); if (GetLastInputInfo(ref info)) { Int32 idleTicks = 0; Int32 tickCount = Environment.TickCount; if (tickCount - info.dwTime < 0) { Int32 tickCountWrapDifference = Int32.MaxValue - info.dwTime; idleTicks = tickCountWrapDifference + tickCount; } else { idleTicks = tickCount - info.dwTime; } return(idleTicks > userIdleThresholdInSeconds * 1000); } return(false); }