private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
        private void CheckIdle()
        {
            LASTINPUTINFO lastInput = new LASTINPUTINFO();
            lastInput.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(lastInput);
            if (!GetLastInputInfo(ref lastInput))
            {
                return;
            }

            uint idleTicks = (uint)Environment.TickCount - lastInput.dwTime;
            if (idleTicks > IdleThresholdMs)
            {
                if (!isIdle)
                {
                    isIdle = true;
                    AddEntry(DateTime.Now.AddMilliseconds(-idleTicks), ActivityType.IdleStart);
                }
            }
            else
            {
                if (isIdle)
                {
                    isIdle = false;
                    AddEntry(DateTime.Now.AddMilliseconds(-idleTicks), ActivityType.IdleEnd);
                }
            }
        }