static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
        private TimeSpan RetrieveIdleTime()
        {
            LASTINPUTINFO lastInputInfo = new LASTINPUTINFO();
            lastInputInfo.cbSize = (uint)LASTINPUTINFO.SizeOf;
            GetLastInputInfo(ref lastInputInfo);

            // Diff between current tickCount and tick count at last activity is
            // the elapsed idle time.
            int elapsedTicks = Environment.TickCount - (int)lastInputInfo.dwTime;

            // The "tick count" is the time in milliseconds since the system started.
            // So the elapsedTicks is expressed in milliseconds
            // Run a system for 24.9 days and you have trouble with this, since
            // it'll wrap and be crazy.
            // Need to fix this!

            if (elapsedTicks > 0) { return new TimeSpan(0, 0, 0, 0, elapsedTicks); }
            else { return new TimeSpan(0); }
        }