示例#1
0
        public static InactivityTimeInfo GetInactiveTimeInfo()
        {
            int systemUptime   = Environment.TickCount,
                lastInputTicks = 0,
                inactiveTicks  = 0;

            LastInputInfo lastInputInfo = new LastInputInfo();

            lastInputInfo.infoSize = (uint)Marshal.SizeOf(lastInputInfo);
            lastInputInfo.downTime = 0;

            if (GetLastInputInfo(ref lastInputInfo))
            {
                lastInputTicks = (int)lastInputInfo.downTime;
                inactiveTicks  = systemUptime - lastInputTicks;
            }

            return(new InactivityTimeInfo
            {
                LastInputTime = DateTime.Now.AddMilliseconds(-1 * inactiveTicks),
                InactiveTime = new TimeSpan(0, 0, 0, 0, inactiveTicks),
                SystemUpTimeMilliseconds = systemUptime,
            });
        }
示例#2
0
 static extern bool GetLastInputInfo(ref LastInputInfo refLastInputInfo);