public static LastInputInfo Create() { var result = new LastInputInfo(); result.Size = (uint)Marshal.SizeOf(result); return(result); }
public static Option <LastInputInfo> GetLastInputInfo() { var inputInfo = new LastInputInfo(); inputInfo.cbSize = (uint)Marshal.SizeOf(inputInfo); return(GetLastInputInfo(ref inputInfo)? Some(inputInfo) : None); }
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); }
public static LastInputInfo Create() { LastInputInfo info = new LastInputInfo(); info.cbSize = Marshal.SizeOf(typeof(LastInputInfo)); return(info); }
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; } }
public static TimeSpan GetIdleTimeSpan() { var lastInPut = new LastInputInfo(); lastInPut.cbSize = (uint)Marshal.SizeOf(lastInPut); GetLastInputInfo(ref lastInPut); return(TimeSpan.FromMilliseconds((Environment.TickCount - lastInPut.dwTime))); }
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); }
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); }
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)); }
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()); } }
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)); }
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()); } }
/// <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; } }
/// <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 }; }
/// <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); } }
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()); } }
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; } }
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) { } }
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); }
public static TimeSpan GetIdleTimeSpan() { var lastInPut = new LastInputInfo(); lastInPut.cbSize = (uint)Marshal.SizeOf(lastInPut); GetLastInputInfo(ref lastInPut); return TimeSpan.FromMilliseconds((Environment.TickCount - lastInPut.dwTime)); }
private static extern bool GetLastInputInfo(ref LastInputInfo info);
public static extern bool GetLastInputInfo(ref LastInputInfo info);
/// <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; }
static LastUserInput() { _lastInputInfo = new LastInputInfo(); _lastInputInfo.CbSize = (uint)Marshal.SizeOf(_lastInputInfo); }
public static extern int GetLastInputInfo(ref LastInputInfo lastInputInfo);
static LastUserInput() { lastInPutNfo = new LastInputInfo(); lastInPutNfo.CbSize = (uint)Marshal.SizeOf(lastInPutNfo); }
public static LastInputInfo Create() { var result = new LastInputInfo(); result.Size = (uint)Marshal.SizeOf(result); return result; }
public static LastInputInfo Create() { LastInputInfo info = new LastInputInfo(); info.cbSize = Marshal.SizeOf(typeof (LastInputInfo)); return info; }
private static extern bool GetLastInputInfo(ref LastInputInfo plii);
internal static extern bool GetLastInputInfo(ref LastInputInfo lastinputinfo);
private static extern Boolean GetLastInputInfo(ref LastInputInfo lastInput);
static extern bool GetLastInputInfo(ref LastInputInfo plii);