public static DateTime GetLastInputTime() { LastInputInfo inputInfo = new LastInputInfo { Size = (uint)Marshal.SizeOf(typeof(LastInputInfo)) }; if (!NativeMethods.GetLastInputInfo(ref inputInfo)) { int error = Marshal.GetHRForLastWin32Error(); throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unable to get the last input time: 0x{0:X8}", error)); } return DateTime.UtcNow - TimeSpan.FromMilliseconds(Environment.TickCount - inputInfo.Time); }
internal static extern bool GetLastInputInfo( /* [out] */ ref LastInputInfo lastInputInfo);