Exemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns>Returns information about system idle time.</returns>
        public static IdleTimeInfo GetIdleTimeInfo()
        {
            int systemUptime = Environment.TickCount,
                lastInputTicks = 0,
                idleTicks = 0;

            LASTINPUTINFO lastInputInfo = new LASTINPUTINFO();
            lastInputInfo.CbSize = (uint)Marshal.SizeOf(lastInputInfo);
            lastInputInfo.DwTime = 0;

            if (!GetLastInputInfo(ref lastInputInfo))
                return new IdleTimeInfo
                {
                    LastInputTime = DateTime.Now.AddMilliseconds(-1*idleTicks),
                    IdleTime = new TimeSpan(0, 0, 0, 0, idleTicks),
                    SystemUptimeMilliseconds = systemUptime,
                };
            lastInputTicks = (int)lastInputInfo.DwTime;

            idleTicks = systemUptime - lastInputTicks;

            return new IdleTimeInfo
            {
                LastInputTime = DateTime.Now.AddMilliseconds(-1 * idleTicks),
                IdleTime = new TimeSpan(0, 0, 0, 0, idleTicks),
                SystemUptimeMilliseconds = systemUptime,
            };
        }
Exemplo n.º 2
0
 static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);