コード例 #1
0
            public static LastInputInfo Create()
            {
                var result = new LastInputInfo();

                result.Size = (uint)Marshal.SizeOf(result);
                return(result);
            }
コード例 #2
0
        public static Option <LastInputInfo> GetLastInputInfo()
        {
            var inputInfo = new LastInputInfo();

            inputInfo.cbSize = (uint)Marshal.SizeOf(inputInfo);
            return(GetLastInputInfo(ref inputInfo)? Some(inputInfo) : None);
        }
コード例 #3
0
        public static bool GetLastInputInfo(out DateTime systemStartupTime, out TimeSpan idleTime)
        {
            systemStartupTime = DateTime.MinValue;
            idleTime          = TimeSpan.Zero;

            // Get the system uptime
            var ticksSinceSystemStarted = Environment.TickCount;
            // The tick at which the last input was recorded
            int lastInputTicks;
            // The number of ticks that passed since last input
            int idleTicks;

            // Set the struct
            var lastInputInfo = new LastInputInfo();

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

            // If we have a value from the function
            if (!GetLastInputInfo(ref lastInputInfo))
            {
                return(false);
            }

            // Get the number of ticks at the point when the last activity was seen
            lastInputTicks = (int)lastInputInfo.DwTime;
            // Number of idle ticks = system uptime ticks - number of ticks at last input
            idleTicks = ticksSinceSystemStarted - lastInputTicks;

            systemStartupTime = DateTime.Now.Subtract(TimeSpan.FromMilliseconds(ticksSinceSystemStarted));
            idleTime          = TimeSpan.FromMilliseconds(idleTicks);

            return(true);
        }
コード例 #4
0
            public static LastInputInfo Create()
            {
                LastInputInfo info = new LastInputInfo();

                info.cbSize = Marshal.SizeOf(typeof(LastInputInfo));
                return(info);
            }
コード例 #5
0
        public void RunTask()
        {
            var info = new LastInputInfo();

            info.cbSize = Marshal.SizeOf(info);
            GetLastInputInfo(ref info);
            uint tick = GetTickCount();
            uint msec = tick - info.dwTime;

            //Logger.Debug("Last input was " + (msec / 1000) + " secs ago");
            if (_appContext.IdleState != IdleState.ExtendedIdle && msec > TimeToExtendedIdle)
            {
                Logger.Debug("System is no longer " + _appContext.IdleState + ", now " + IdleState.ExtendedIdle);
                _appContext.IdleState = IdleState.ExtendedIdle;
            }
            else if (_appContext.IdleState == IdleState.InUse && msec > TimeToIdle)
            {
                Logger.Debug("System is no longer " + _appContext.IdleState + ", now " + IdleState.Idle);
                _appContext.IdleState = IdleState.Idle;
            }
            else if (_appContext.IdleState != IdleState.InUse && msec < TimeToIdle)
            {
                Logger.Debug("System is no longer " + _appContext.IdleState + ", now " + IdleState.InUse);
                _appContext.IdleState = IdleState.InUse;
            }
        }
コード例 #6
0
        public static TimeSpan GetIdleTimeSpan()
        {
            var lastInPut = new LastInputInfo();

            lastInPut.cbSize = (uint)Marshal.SizeOf(lastInPut);
            GetLastInputInfo(ref lastInPut);
            return(TimeSpan.FromMilliseconds((Environment.TickCount - lastInPut.dwTime)));
        }
コード例 #7
0
        private bool IsUserActive()
        {
            LastInputInfo info = LastInputInfo.Create();

            if (!Win32Bindings.GetLastInputInfo(ref info))
            {
                throw new Exception("Could not get time of last user activity");
            }

            long idleTime = Environment.TickCount - info.dwTime;

            return(idleTime <= Config.TimeToIdle);
        }
コード例 #8
0
        public static long GetLastInputTime()
        {
            var lastInput = new LastInputInfo();

            lastInput.CbSize = (uint)Marshal.SizeOf(lastInput);

            if (!GetLastInputInfo(ref lastInput))
            {
                throw new Exception(GetLastError().ToString());
            }

            return(lastInput.DwTime);
        }
コード例 #9
0
        public static DateTime GetLastInputTime()
        {
            LastInputInfo inputInfo = new LastInputInfo {
                Size = (uint)Marshal.SizeOf(typeof(LastInputInfo))
            };

            if (!NativeMethods.GetLastInputInfo(ref inputInfo))
            {
                int error = Marshal.GetHRForLastWin32Error();
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unable to get the last input time: 0x{0:X8}", error));
            }

            return(DateTime.UtcNow - TimeSpan.FromMilliseconds(Environment.TickCount - inputInfo.Time));
        }
コード例 #10
0
        public static TimeSpan GetTimeSinceLastInput()
        {
            var lastInputInfo = new LastInputInfo();

            lastInputInfo.CbSize = (uint)Marshal.SizeOf(lastInputInfo);

            if (GetLastInputInfo(ref lastInputInfo))
            {
                return(TimeSpan.FromMilliseconds(Environment.TickCount64 - lastInputInfo.DwTime));
            }
            else
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }
コード例 #11
0
        public static TimeSpan GetCurrentIdleTime()
        {
            var idleTime      = 0;
            var lastInputInfo = new LastInputInfo();

            lastInputInfo.cbSize = Marshal.SizeOf(lastInputInfo);
            lastInputInfo.dwTime = 0;

            if (GetLastInputInfo(out lastInputInfo))
            {
                idleTime = Environment.TickCount - lastInputInfo.dwTime;
            }

            return(TimeSpan.FromMilliseconds(idleTime));
        }
コード例 #12
0
        private static TimeSpan GetLastInputTime()
        {
            var plii = new LastInputInfo();

            plii.cbSize = (uint)Marshal.SizeOf(plii);

            if (GetLastInputInfo(ref plii))
            {
                return(TimeSpan.FromMilliseconds(Environment.TickCount - plii.dwTime));
            }
            else
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }
コード例 #13
0
ファイル: Win32Library.cs プロジェクト: haraldr/om3controller
        /// <summary>
        /// Returns the user idle time in seconds.
        /// </summary>
        /// <returns>User idle time in seconds.</returns>
        public static int GetUserIdleTime()
        {
            LastInputInfo lInfo = new LastInputInfo();
              lInfo.Size = LastInputInfo.SizeOf;

              if (GetLastInputInfo(ref lInfo))
              {
            int lEnvTicks = Environment.TickCount;
            int lIdleTicks = lEnvTicks - lInfo.Time;
            return (lIdleTicks / 1000);
              }
              else
              {
            return 0;
              }
        }
コード例 #14
0
ファイル: PInvoke.cs プロジェクト: nohros/aion
        /// <summary>
        /// Gets time in seconds since the last user input.
        /// </summary>
        /// <returns>
        /// The time in seconds since the last user input.
        /// </returns>
        public static IdleTimeInfo GetSystemIdleTime()
        {
            var last_input_info = new LastInputInfo();
              last_input_info.cbSize = (uint) Marshal.SizeOf(last_input_info);
              last_input_info.dwTime = 0;

              uint last_input_tick = 0;
              var env_ticks = (uint) System.Environment.TickCount;
              if (GetLastInputInfo(ref last_input_info)) {
            last_input_tick = last_input_info.dwTime;
              }
              return new IdleTimeInfo {
            Timestamp = DateTime.Now.ToUnixEpoch(),
            LastInputTime = last_input_tick,
            MachineUpTime = env_ticks
              };
        }
コード例 #15
0
ファイル: Win32Library.cs プロジェクト: haraldr/om3controller
        /// <summary>
        /// Returns the user idle time in seconds.
        /// </summary>
        /// <returns>User idle time in seconds.</returns>
        public static int GetUserIdleTime()
        {
            LastInputInfo lInfo = new LastInputInfo();

            lInfo.Size = LastInputInfo.SizeOf;

            if (GetLastInputInfo(ref lInfo))
            {
                int lEnvTicks  = Environment.TickCount;
                int lIdleTicks = lEnvTicks - lInfo.Time;
                return(lIdleTicks / 1000);
            }
            else
            {
                return(0);
            }
        }
コード例 #16
0
        public override IEnumerable <CommandDTOBase?> Execute(string[] args)
        {
            var lastInputInfo = new LastInputInfo();

            lastInputInfo.Size = (uint)Marshal.SizeOf(lastInputInfo);

            if (GetLastInputInfo(ref lastInputInfo))
            {
                var currentUser = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
                yield return(new IdleTimeDTO(
                                 currentUser,
                                 ((uint)Environment.TickCount - lastInputInfo.Time)
                                 ));
            }
            else
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }
コード例 #17
0
ファイル: DetectIdleTask.cs プロジェクト: gwupe/Gwupe
 public void RunTask()
 {
     var info = new LastInputInfo();
     info.cbSize = Marshal.SizeOf(info);
     GetLastInputInfo(ref info);
     uint tick = GetTickCount();
     uint msec = tick - info.dwTime;
     //Logger.Debug("Last input was " + (msec / 1000) + " secs ago");
     if (_appContext.IdleState != IdleState.ExtendedIdle && msec > TimeToExtendedIdle)
     {
         Logger.Debug("System is no longer " + _appContext.IdleState + ", now " + IdleState.ExtendedIdle);
         _appContext.IdleState = IdleState.ExtendedIdle;
     }
     else if (_appContext.IdleState == IdleState.InUse && msec > TimeToIdle)
     {
         Logger.Debug("System is no longer " + _appContext.IdleState + ", now " + IdleState.Idle);
         _appContext.IdleState = IdleState.Idle;
     } else if(_appContext.IdleState != IdleState.InUse && msec < TimeToIdle)
     {
         Logger.Debug("System is no longer " + _appContext.IdleState + ", now " + IdleState.InUse);
         _appContext.IdleState = IdleState.InUse;
     }
 }
コード例 #18
0
        private static void PrintCurrentUserIdleTime()
        {
            try
            {
                Beaprint.MainPrint("Current User Idle Time");

                var lastInputInfo = new LastInputInfo();
                lastInputInfo.Size = (uint)Marshal.SizeOf(lastInputInfo);

                if (User32.GetLastInputInfo(ref lastInputInfo))
                {
                    var currentUser         = WindowsIdentity.GetCurrent().Name;
                    var idleTimeMiliSeconds = (uint)Environment.TickCount - lastInputInfo.Time;
                    var timeSpan            = TimeSpan.FromMilliseconds(idleTimeMiliSeconds);
                    var idleTimeString      = $"{timeSpan.Hours:D2}h:{timeSpan.Minutes:D2}m:{timeSpan.Seconds:D2}s:{timeSpan.Milliseconds:D3}ms";

                    Beaprint.NoColorPrint($"   Current User   :     {currentUser}\n" +
                                          $"   Idle Time      :     {idleTimeString}");
                }
            }
            catch (Exception ex)
            {
            }
        }
コード例 #19
0
        public static Boolean IsUserIdle(Int32 userIdleThresholdInSeconds)
        {
            LastInputInfo info = LastInputInfo.Create();

            if (GetLastInputInfo(ref info))
            {
                Int32 idleTicks = 0;
                Int32 tickCount = Environment.TickCount;

                if (tickCount - info.dwTime < 0)
                {
                    Int32 tickCountWrapDifference = Int32.MaxValue - info.dwTime;
                    idleTicks = tickCountWrapDifference + tickCount;
                }
                else
                {
                    idleTicks = tickCount - info.dwTime;
                }

                return(idleTicks > userIdleThresholdInSeconds * 1000);
            }

            return(false);
        }
コード例 #20
0
ファイル: MainForm.cs プロジェクト: JonnyFunFun/IdleMiner
 public static TimeSpan GetIdleTimeSpan()
 {
     var lastInPut = new LastInputInfo();
     lastInPut.cbSize = (uint)Marshal.SizeOf(lastInPut);
     GetLastInputInfo(ref lastInPut);
     return TimeSpan.FromMilliseconds((Environment.TickCount - lastInPut.dwTime));
 }
コード例 #21
0
ファイル: DetectIdleTask.cs プロジェクト: gwupe/Gwupe
 private static extern bool GetLastInputInfo(ref LastInputInfo info);
コード例 #22
0
 public static extern bool GetLastInputInfo(ref LastInputInfo info);
コード例 #23
0
        /// <summary> 
        /// Returns the number of milliseconds since the last user input (or mouse movement) 
        /// </summary> 
        private static uint GetIdleTime()
        {
            LastInputInfo lastInput = new LastInputInfo();
            lastInput.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(lastInput);
            GetLastInputInfo(ref lastInput);

            return (uint)Environment.TickCount - lastInput.dwTime;
        }
コード例 #24
0
 static LastUserInput()
 {
     _lastInputInfo        = new LastInputInfo();
     _lastInputInfo.CbSize = (uint)Marshal.SizeOf(_lastInputInfo);
 }
コード例 #25
0
ファイル: DLLInvoke.cs プロジェクト: LJea/TimerWatcher
 public static extern int GetLastInputInfo(ref LastInputInfo lastInputInfo);
コード例 #26
0
 static LastUserInput()
 {
     lastInPutNfo        = new LastInputInfo();
     lastInPutNfo.CbSize = (uint)Marshal.SizeOf(lastInPutNfo);
 }
コード例 #27
0
 public static LastInputInfo Create()
 {
     var result = new LastInputInfo();
     result.Size = (uint)Marshal.SizeOf(result);
     return result;
 }
コード例 #28
0
 public static LastInputInfo Create()
 {
     LastInputInfo info = new LastInputInfo();
     info.cbSize = Marshal.SizeOf(typeof (LastInputInfo));
     return info;
 }
コード例 #29
0
 private static extern bool GetLastInputInfo(ref LastInputInfo info);
コード例 #30
0
 public static extern bool GetLastInputInfo(ref LastInputInfo info);
コード例 #31
0
ファイル: MainForm.cs プロジェクト: JonnyFunFun/IdleMiner
 private static extern bool GetLastInputInfo(ref LastInputInfo plii);
コード例 #32
0
 internal static extern bool GetLastInputInfo(ref LastInputInfo lastinputinfo);
コード例 #33
0
 private static extern Boolean GetLastInputInfo(ref LastInputInfo lastInput);
コード例 #34
0
 static extern bool GetLastInputInfo(ref LastInputInfo plii);
コード例 #35
0
 private static extern Boolean GetLastInputInfo(ref LastInputInfo lastInput);