示例#1
0
 private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
示例#2
0
        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);
                }
            }
        }