static uint GetLastInputTime() { uint idleTime = 0; LastInputInfo lastInputInfo = new LastInputInfo(); lastInputInfo.cbSize = (uint)Marshal.SizeOf(lastInputInfo); lastInputInfo.dwTime = 0; uint envTicks = (uint)Environment.TickCount; if (GetLastInputInfo(ref lastInputInfo)) { uint lastInputTick = lastInputInfo.dwTime; idleTime = (envTicks - lastInputTick); } return((idleTime > 0) ? (idleTime / 1000) : idleTime); }
private static extern bool GetLastInputInfo(ref LastInputInfo ptrInputInfo);