Beispiel #1
0
        private void SetIdleTime()
        {
            int systemUptime   = Environment.TickCount;
            int LastInputTicks = 0;
            int IdleTicks      = 0;

            Win32Wrapper.LASTINPUTINFO LastInputInfo = new Win32Wrapper.LASTINPUTINFO();
            LastInputInfo.cbSize = (uint)Marshal.SizeOf(LastInputInfo);
            LastInputInfo.dwTime = 0;

            if (Win32Wrapper.GetLastInputInfo(ref LastInputInfo))
            {
                LastInputTicks = (int)LastInputInfo.dwTime;
                IdleTicks      = systemUptime - LastInputTicks;
            }

            _idleTime = (IdleTicks / 1000 / 60) + 1;
        }
Beispiel #2
0
        private void SetState()
        {
            SetIdleTime();

            var state = _states.FirstOrDefault(s => s.MenuItem.Checked);

            if ((state.Period != -1 && _idleTime > state.Period) || (_IsLock && (disableOnLockScreenToolStripMenuItem.Checked)))
            {
                _prevExecutionState = Win32Wrapper.SetThreadExecutionState(Win32Wrapper.ES_CONTINUOUS);
            }
            else
            {
                _prevExecutionState = Win32Wrapper.SetThreadExecutionState(Win32Wrapper.ES_CONTINUOUS | Win32Wrapper.ES_DISPLAY_REQUIRED | Win32Wrapper.ES_SYSTEM_REQUIRED);
            }

            if (_IsLock && monitorOffOnLockScreenToolStripMenuItem.Checked && !_IsDarkOnLock)
            {
                Win32Wrapper.SendMessage(this.Handle, Win32Wrapper.WM_SYSCOMMAND, (IntPtr)Win32Wrapper.SC_MONITORPOWER, (IntPtr)2);
                _IsDarkOnLock = true;
            }
        }