private void CheckUserInactivity() { try { tagLASTINPUTINFO LastInput = new tagLASTINPUTINFO(); Int32 IdleTime; LastInput.cbSize = (uint)Marshal.SizeOf(LastInput); LastInput.dwTime = 0; if (GetLastInputInfo(ref LastInput)) { IdleTime = System.Environment.TickCount - LastInput.dwTime; Trace.WriteLine($"*** IdleTime: {IdleTime}ms ***"); if (IdleTime > 300000) { Dispatcher.Invoke(new UpdateUICallBack(ForceLogOff)); } } } catch (Exception ex) { Error.ReportOrLog(ex); } }
private void timer_Elapsed(object sender, ElapsedEventArgs e) { tagLASTINPUTINFO lastInput = new tagLASTINPUTINFO(); lastInput.cbSize = (uint)Marshal.SizeOf(lastInput); lastInput.dwTime = 0; if (GetLastInputInfo(ref lastInput)) { int idleTime = Environment.TickCount - lastInput.dwTime; if (idleTime > 50) { if (idleTime > this._idleIndicator) { bool shouldLaunchEvent = !this._inIdle && this.UserIdleDetected != null; if (shouldLaunchEvent) { this.UserIdleDetected(this, EventArgs.Empty); } this._inIdle = true; } } else { bool shouldLaunchEvent = this._inIdle && this.UserIdleInterrupted != null; if (shouldLaunchEvent) { this.UserIdleInterrupted(this, EventArgs.Empty); } this._inIdle = false; } } }
private void timer1_Tick(object sender, EventArgs e) { tagLASTINPUTINFO LastInput = new tagLASTINPUTINFO(); Int32 IdleTime; LastInput.cbSize = (uint)Marshal.SizeOf(LastInput); LastInput.dwTime = 0; //This is where I am going to put a check for a running program if (GetLastInputInfo(ref LastInput)) { IdleTime = System.Environment.TickCount - LastInput.dwTime; //DEBUGGING Text Field // label1.Text = IdleTime + " ms " + rowCounter + "run time:" + "last input" + LastInput.dwTime + "App start" + ((DateTime.UtcNow - Process.GetCurrentProcess().StartTime.ToUniversalTime()).TotalMilliseconds); // label1.Text = idleStart +" "+ idleEnd; } IdleTime = System.Environment.TickCount - LastInput.dwTime; //Check the idle time. If less then 100ms close the application. //The Reason for 100ms is if it is set to 0, the program doesn't always catch the user input. If it is set to high the program closes right away. if (IdleTime <= 100) { Application.Exit(); } //This is our time check. If we were to use the system idle time the program would close at the time the //user stopped the keyboard/mouse input We are starting the idletime based on when our app lauches if ((DateTime.UtcNow - Process.GetCurrentProcess().StartTime.ToUniversalTime()).TotalMilliseconds > 780000) { if (popupCounter == 0) { //increment our popup counter and show our message box. Force it to main focus over all other windows //MessageBoxOptions 0x40000 popupCounter++; DialogResult AutoResult = MessageBox.Show("This System will reboot in 2 minutes if it is left idle", "End Session Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000); } } //If it is 900000ms or 15 minutes and greater since the launch or the app, force close all programs and restart. if ((DateTime.UtcNow - Process.GetCurrentProcess().StartTime.ToUniversalTime()).TotalMilliseconds > 900000) { // SendKeys.Send("{Enter}"); System.Diagnostics.Process.Start("shutdown.exe", "-r -f -t 0"); } }
private void timerLastInput_Tick(object sender, EventArgs e) { tagLASTINPUTINFO LastInput = new tagLASTINPUTINFO(); Int32 IdleTime; LastInput.cbSize = (uint)Marshal.SizeOf(LastInput); LastInput.dwTime = 0; if (GetLastInputInfo(ref LastInput)) { IdleTime = System.Environment.TickCount - LastInput.dwTime; _idleTime = IdleTime; } }
public static int IdleTime() //In seconds { tagLASTINPUTINFO LastInput = new tagLASTINPUTINFO(); int indletimmme = 0; LastInput.cbSize = (uint)Marshal.SizeOf(LastInput); LastInput.dwTime = 0; if (GetLastInputInfo(ref LastInput)) { indletimmme = System.Environment.TickCount - LastInput.dwTime; return(indletimmme / 1000); } return(0); }
// Figure out how long we have been idle for private Int32 GetIdleTime() { tagLASTINPUTINFO LastInput = new tagLASTINPUTINFO(); Int32 IdleTime = -1; LastInput.cbSize = (uint)Marshal.SizeOf(LastInput); LastInput.dwTime = 0; if (GetLastInputInfo(ref LastInput)) { IdleTime = System.Environment.TickCount - LastInput.dwTime; } return(IdleTime); }
public static int GetNrMinuteInactivitate() { tagLASTINPUTINFO LastInput = new tagLASTINPUTINFO(); Int32 IdleTime = 0; LastInput.cbSize = (uint)Marshal.SizeOf(LastInput); LastInput.dwTime = 0; if (GetLastInputInfo(ref LastInput)) { IdleTime = System.Environment.TickCount - LastInput.dwTime; } return(IdleTime / 60000); }
private void timer1_Tick(object sender, EventArgs e) { tagLASTINPUTINFO LastInput = new tagLASTINPUTINFO(); Int32 IdleTime; LastInput.cbSize = (uint)Marshal.SizeOf(LastInput); LastInput.dwTime = 0; if (GetLastInputInfo(ref LastInput)) { IdleTime = System.Environment.TickCount - LastInput.dwTime; if (IdleTime > 10000) { axWindowsMediaPlayer1.Ctlcontrols.pause(); timer1.Stop(); MessageBox.Show("Do you wish to continue?"); } timer1.Start(); axWindowsMediaPlayer1.Ctlcontrols.play(); } }
private static void timer1_Tick(object sender, EventArgs e) { int mins = int.Parse(ConfigurationManager.AppSettings["timeout"]); tagLASTINPUTINFO LastInput = new tagLASTINPUTINFO(); Int32 IdleTime; LastInput.cbSize = (uint)Marshal.SizeOf(LastInput); LastInput.dwTime = 0; if (GetLastInputInfo(ref LastInput)) { IdleTime = System.Environment.TickCount - LastInput.dwTime; //label1.Text = IdleTime + "ms"; if (IdleTime > (60000*mins)) { timer1.Stop(); MessageBox.Show("You have been idle for " + mins + ", please Refresh Your Data before continue!","Idle",MessageBoxButtons.OK,MessageBoxIcon.Information); //stopIdleTimer(); } } }
private void UpdateIdleEffects(EffectsEngine.EffectFrame newFrame) { tagLASTINPUTINFO LastInput = new tagLASTINPUTINFO(); Int32 IdleTime; LastInput.cbSize = (uint)Marshal.SizeOf(LastInput); LastInput.dwTime = 0; if (ActiveProcessMonitor.GetLastInputInfo(ref LastInput)) { IdleTime = System.Environment.TickCount - LastInput.dwTime; if (IdleTime >= Global.Configuration.idle_delay * 60 * 1000) { if (!(Global.Configuration.time_based_dimming_enabled && Utils.Time.IsCurrentTimeBetween(Global.Configuration.time_based_dimming_start_hour, Global.Configuration.time_based_dimming_start_minute, Global.Configuration.time_based_dimming_end_hour, Global.Configuration.time_based_dimming_end_minute)) ) { idle_e.UpdateLights(newFrame); } } } }
private void UpdateIdleEffects(EffectsEngine.EffectFrame newFrame) { tagLASTINPUTINFO LastInput = new tagLASTINPUTINFO(); Int32 IdleTime; LastInput.cbSize = (uint)Marshal.SizeOf(LastInput); LastInput.dwTime = 0; if (ActiveProcessMonitor.GetLastInputInfo(ref LastInput)) { IdleTime = System.Environment.TickCount - LastInput.dwTime; if (IdleTime >= Global.Configuration.IdleDelay * 60 * 1000) { if (!(Global.Configuration.TimeBasedDimmingEnabled && Utils.Time.IsCurrentTimeBetween(Global.Configuration.TimeBasedDimmingStartHour, Global.Configuration.TimeBasedDimmingStartMinute, Global.Configuration.TimeBasedDimmingEndHour, Global.Configuration.TimeBasedDimmingEndMinute)) ) { UpdateEvent(idle_e, newFrame); } } } }
// --| Idle timer scanner // --| We check if the computer is in idle state private void IdleChekTimer_Tick(object sender, EventArgs e) { // --| If there is no scanner started and checkbox "Auto-Start if system is idle" is ENABLED then we start our scanning time if (chkBox_Idle.Checked == true && ScannerTimer.Enabled == false && timer2.Enabled == false) { // --| Useful stuff to be able to get if system is idling tagLASTINPUTINFO LastInput = new tagLASTINPUTINFO(); Int32 IdleTime; double IdleTimeInMinutes; LastInput.cbSize = (uint)Marshal.SizeOf(LastInput); LastInput.dwTime = 0; if (GetLastInputInfo(ref LastInput)) { // --| Get idle time in milliseconds and convert them to minutes IdleTime = System.Environment.TickCount - LastInput.dwTime; IdleTimeInMinutes = TimeSpan.FromMilliseconds(IdleTime).TotalMinutes; // --| If system is idle is equal or more minutes that our specified time from combobox "IDLE Control" we enable the scanner // --| We also disable Start Scanner button. if (IdleTimeInMinutes >= IdleInterval) { if (ScannerTimer.Enabled != true) { // --| Get the current cursor position again and start the scanner CursorPositionX = Cursor.Position.X; CursorPositionY = Cursor.Position.Y; ScannerTimer.Start(); ScannerTimer.Enabled = true; } } } } }
private void Timer_Tick(object sender, EventArgs e) { if (process != null && process.HasExited) { process.Start(); } string timeout = ConfigurationManager.AppSettings["TimeOut"]; ///Idle time detection tagLASTINPUTINFO LastInput = new tagLASTINPUTINFO(); LastInput.cbSize = (uint)Marshal.SizeOf(LastInput); LastInput.dwTime = 0; if (GetLastInputInfo(ref LastInput)) { IdleTime = System.Environment.TickCount - LastInput.dwTime; IdleTimelbl.Text = IdleTime / 1000 + " sec"; if ((IdleTime / 1000) != 0 && (IdleTime / 1000) % Convert.ToInt16(timeout) == 0) { RestartProcess(); } } }
public void GameStateUpdate(IGameState gs) { //Debug.WriteLine("Received gs!"); //Global.logger.LogLine(gs.ToString(), Logging_Level.None, false); if (Global.Configuration.detection_mode == Settings.ApplicationDetectionMode.ForegroroundApp && (currentTick >= nextProcessNameUpdate)) { process_path = GetActiveWindowsProcessname(); nextProcessNameUpdate = currentTick + 1000L; } string process_name = System.IO.Path.GetFileName(process_path).ToLowerInvariant(); if (Global.Configuration.excluded_programs.Contains(process_name)) { return; } EffectsEngine.EffectFrame newframe = new EffectsEngine.EffectFrame(); try { bool resolved_state = false; switch (Newtonsoft.Json.Linq.JObject.Parse(gs.GetNode("provider")).GetValue("appid").ToString()) { case "570": if (process_name.EndsWith("dota2.exe") && profiles.ContainsKey(process_name) && profiles[process_name].IsEnabled()) { profiles[process_name].UpdateLights(newframe, new Profiles.Dota_2.GSI.GameState_Dota2(gs)); resolved_state = true; } break; case "730": if (process_name.EndsWith("csgo.exe") && profiles.ContainsKey(process_name) && profiles[process_name].IsEnabled()) { profiles[process_name].UpdateLights(newframe, new Profiles.CSGO.GSI.GameState_CSGO(gs)); resolved_state = true; } break; case "218620": if (process_name.EndsWith("payday2_win32_release.exe") && profiles.ContainsKey(process_name) && profiles[process_name].IsEnabled()) { profiles[process_name].UpdateLights(newframe, new Profiles.Payday_2.GSI.GameState_PD2(gs)); resolved_state = true; } break; case "0": if (process_name.EndsWith("gta5.exe") && Newtonsoft.Json.Linq.JObject.Parse(gs.GetNode("provider")).GetValue("name").ToString().ToLowerInvariant().Equals("gta5.exe") && profiles.ContainsKey(process_name) && profiles[process_name].IsEnabled()) { profiles[process_name].UpdateLights(newframe, gs as Profiles.GTA5.GSI.GameState_GTA5); resolved_state = true; } else if (Newtonsoft.Json.Linq.JObject.Parse(gs.GetNode("provider")).GetValue("name").ToString().ToLowerInvariant().Equals("skype.exe") && skype_overlay.IsEnabled()) { skype_overlay.UpdateLights(newframe, new Profiles.Overlays.SkypeOverlay.State_SkypeOverlay(gs)); } else { if (gs is GameState_Wrapper && Global.Configuration.allow_all_logitech_bitmaps) { string gs_process_name = Newtonsoft.Json.Linq.JObject.Parse(gs.GetNode("provider")).GetValue("name").ToString().ToLowerInvariant(); if (!profiles.ContainsKey(gs_process_name)) { profiles.Add(gs_process_name, new GameEvent_Aurora_Wrapper()); } if (process_name.EndsWith(gs_process_name)) { profiles[gs_process_name].UpdateLights(newframe, gs as GameState_Wrapper); resolved_state = true; } else { (profiles[gs_process_name] as GameEvent_Aurora_Wrapper).UpdateWrapperLights(gs as GameState_Wrapper); } } } break; default: break; } tagLASTINPUTINFO LastInput = new tagLASTINPUTINFO(); Int32 IdleTime; LastInput.cbSize = (uint)Marshal.SizeOf(LastInput); LastInput.dwTime = 0; if (GetLastInputInfo(ref LastInput) && resolved_state) { IdleTime = System.Environment.TickCount - LastInput.dwTime; if (IdleTime >= Global.Configuration.idle_delay * 60 * 1000) { if (!(Global.Configuration.time_based_dimming_enabled && Global.Configuration.time_based_dimming_affect_games && Utils.Time.IsCurrentTimeBetween(Global.Configuration.time_based_dimming_start_hour, Global.Configuration.time_based_dimming_start_minute, Global.Configuration.time_based_dimming_end_hour, Global.Configuration.time_based_dimming_end_minute)) ) { idle_e.UpdateLights(newframe); } } } if (!(Global.Configuration.time_based_dimming_enabled && Global.Configuration.time_based_dimming_affect_games && Utils.Time.IsCurrentTimeBetween(Global.Configuration.time_based_dimming_start_hour, Global.Configuration.time_based_dimming_start_minute, Global.Configuration.time_based_dimming_end_hour, Global.Configuration.time_based_dimming_end_minute)) ) { if (resolved_state) { //Add overlays TimedListObject[] overlay_events = overlays.ToArray(); foreach (TimedListObject evnt in overlay_events) { if ((evnt.item as LightEvent).IsEnabled()) { (evnt.item as LightEvent).UpdateLights(newframe); } } Global.effengine.PushFrame(newframe); } } } catch (Exception e) { Global.logger.LogLine("Exception during GameStateUpdate(), error: " + e, Logging_Level.Warning); } }
public static extern Boolean GetLastInputInfo(ref tagLASTINPUTINFO plii);
private void Update() { if (Global.Configuration.detection_mode == Settings.ApplicationDetectionMode.ForegroroundApp && (currentTick >= nextProcessNameUpdate)) { process_path = GetActiveWindowsProcessname(); nextProcessNameUpdate = currentTick + 1000L; } string process_name = System.IO.Path.GetFileName(process_path).ToLowerInvariant(); if (Global.Configuration.excluded_programs.Contains(process_name)) { return; } EffectsEngine.EffectFrame newframe = new EffectsEngine.EffectFrame(); tagLASTINPUTINFO LastInput = new tagLASTINPUTINFO(); Int32 IdleTime; LastInput.cbSize = (uint)Marshal.SizeOf(LastInput); LastInput.dwTime = 0; if (GetLastInputInfo(ref LastInput)) { IdleTime = System.Environment.TickCount - LastInput.dwTime; if (IdleTime >= Global.Configuration.idle_delay * 60 * 1000) { if (!(Global.Configuration.time_based_dimming_enabled && Utils.Time.IsCurrentTimeBetween(Global.Configuration.time_based_dimming_start_hour, Global.Configuration.time_based_dimming_start_minute, Global.Configuration.time_based_dimming_end_hour, Global.Configuration.time_based_dimming_end_minute)) ) { idle_e.UpdateLights(newframe); } } } if (Global.Configuration.additional_profiles.ContainsKey(process_name) && (Global.Configuration.additional_profiles[process_name].Settings as GenericApplicationSettings).isEnabled) { Global.dev_manager.InitializeOnce(); Global.Configuration.additional_profiles[process_name].Event.UpdateLights(newframe); /*if (profiles.ContainsKey(process_name)) * { * profiles[process_name] * } * else * { * Event_GenericApplication app_event = new Event_GenericApplication(); * app_event.UpdateLights(newframe); * profiles.Add(process_name, app_event); * }*/ } else if (preview_mode == PreviewType.GenericApplication && Global.Configuration.additional_profiles.ContainsKey(preview_mode_profile_key) && (Global.Configuration.additional_profiles[preview_mode_profile_key].Settings as GenericApplicationSettings).isEnabled) { Global.dev_manager.InitializeOnce(); Global.Configuration.additional_profiles[preview_mode_profile_key].Event.UpdateLights(newframe); /*if (profiles.ContainsKey(preview_mode_profile_key)) * profiles[preview_mode_profile_key].UpdateLights(newframe); * else * { * Event_GenericApplication app_event = new Event_GenericApplication(); * app_event.UpdateLights(newframe); * profiles.Add(preview_mode_profile_key, app_event); * }*/ } else if (preview_mode == PreviewType.Predefined && profiles.ContainsKey(preview_mode_profile_key) && profiles[preview_mode_profile_key].IsEnabled()) { Global.dev_manager.InitializeOnce(); profiles[preview_mode_profile_key].UpdateLights(newframe); } else if (profiles.ContainsKey(process_name) && profiles[process_name].IsEnabled()) { if (process_name.Equals("csgo.exe")) { //Update timer set to 100 ticks a second for CSGO for Smooth Bomb Effect timer_interval = 10; // in miliseconds } else { //UPDATE at 30 ticks per second for rest. timer_interval = 33; } if (!(Global.Configuration.time_based_dimming_enabled && Global.Configuration.time_based_dimming_affect_games && Utils.Time.IsCurrentTimeBetween(Global.Configuration.time_based_dimming_start_hour, Global.Configuration.time_based_dimming_start_minute, Global.Configuration.time_based_dimming_end_hour, Global.Configuration.time_based_dimming_end_minute)) ) { Global.dev_manager.InitializeOnce(); profiles[process_name].UpdateLights(newframe); } } else if (Global.Configuration.allow_wrappers_in_background && Global.net_listener != null && Global.net_listener.IsWrapperConnected && profiles.ContainsKey(Global.net_listener.WrappedProcess) && profiles[Global.net_listener.WrappedProcess].IsEnabled()) { timer_interval = 33; // in miliseconds if (!(Global.Configuration.time_based_dimming_enabled && Global.Configuration.time_based_dimming_affect_games && Utils.Time.IsCurrentTimeBetween(Global.Configuration.time_based_dimming_start_hour, Global.Configuration.time_based_dimming_start_minute, Global.Configuration.time_based_dimming_end_hour, Global.Configuration.time_based_dimming_end_minute)) ) { Global.dev_manager.InitializeOnce(); profiles[Global.net_listener.WrappedProcess].UpdateLights(newframe); } } else { timer_interval = (int)(1000.0D / 30); //50 in miliseconds if (!(Global.Configuration.time_based_dimming_enabled && Utils.Time.IsCurrentTimeBetween(Global.Configuration.time_based_dimming_start_hour, Global.Configuration.time_based_dimming_start_minute, Global.Configuration.time_based_dimming_end_hour, Global.Configuration.time_based_dimming_end_minute)) ) { if (!(Global.Configuration.desktop_profile.Settings as DesktopSettings).isEnabled) { Global.dev_manager.Shutdown(); } else { Global.dev_manager.InitializeOnce(); desktop_e.UpdateLights(newframe); } } } //Add overlays TimedListObject[] overlay_events = overlays.ToArray(); foreach (TimedListObject evnt in overlay_events) { if ((evnt.item as LightEvent).IsEnabled()) { (evnt.item as LightEvent).UpdateLights(newframe); } } Global.effengine.PushFrame(newframe); currentTick += (long)timer_interval; }
private static extern Boolean GetLastInputInfo(ref tagLASTINPUTINFO plii);