コード例 #1
0
        public static IdleTimeInfo GetIdleTimeInfo()
        {
            int systemUptime = Environment.TickCount;
            int idleTicks = 0;

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

            if (GetLastInputInfo(ref lastInputInfo))
            {
                int 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
            };
        }
コード例 #2
0
 private static extern bool GetLastInputInfo(ref Lastinputinfo plii);