Ejemplo n.º 1
0
        private void TrackTime()
        {
            if (IsTheTimecardStillCurrent())
            {
                // Track total time
                Timecard.Total = Timecard.Total.Add(TimeSpan.FromSeconds(1));

                // Track overtime
                if (Timecard.Total >= TimeSpan.FromHours(settings.TotalDailyWorkingHours))
                {
                    Timecard.Overtime = Timecard.Overtime.Add(TimeSpan.FromSeconds(1));
                }

                // Track idle time
                TimeSpan timeSpentidle = TimeSpan.FromMilliseconds(IdleTimeFinder.GetIdleTime());
                if (timeSpentidle >= acceptedIdleTime)
                {
                    Timecard.Idle = Timecard.Idle.Add(TimeSpan.FromSeconds(1));
                }

                // Track punch out time
                Timecard.Stop = DateTime.UtcNow;
            }
            else
            {
                startANewDay();
            }
        }
Ejemplo n.º 2
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            var idleTime = IdleTimeFinder.GetIdleTime();

            IdleTextBox.Text      = idleTime.ToString(TimeSpanFormat);
            StartedOnTextBox.Text = (DateTime.Now - Started).ToString(TimeSpanFormat);
        }
Ejemplo n.º 3
0
        private void InterceptKeys_OnKeyDown(object sender, KeyEventArgs e)
        {
            Logger.Info($"Key Pressed : {e.KeyCode} key press after {IdleTimeFinder.GetIdleTime()}");
            if (e.KeyCode == Keys.Escape)
            {
                var senseAdProcessor = this.clixSenseAdProcessor;
                if (senseAdProcessor != null)
                {
                    senseAdProcessor.StopAllProcessing = true;
                    senseAdProcessor.CaptureCatImage   = false;
                }

                var ptcAdProcessor = this.nemoAdProcessor;
                if (ptcAdProcessor != null)
                {
                    ptcAdProcessor.StopAllProcessing = true;
                }
                Logger.Info($"{Resources.FindImageInScreenShot_InterceptKeys_OnKeyDown_Stopping_all_Processing}");
                this.notifyIcon1.Icon            = SystemIcons.Exclamation;
                this.notifyIcon1.BalloonTipTitle = "Stop";
                this.notifyIcon1.BalloonTipText  = Resources.FindImageInScreenShot_InterceptKeys_OnKeyDown_Stopping_all_Processing;
                this.notifyIcon1.BalloonTipIcon  = ToolTipIcon.Warning;
                this.notifyIcon1.ShowBalloonTip(5000);
            }
        }
Ejemplo n.º 4
0
        private void CheckUserInput(object sender, EventArgs e)
        {
            TimeSpan ts = TimeSpan.FromMilliseconds(IdleTimeFinder.GetIdleTime());

            if (ts.TotalSeconds > 30)
            {
                Hide();
            }
        }
Ejemplo n.º 5
0
        private void ActivityCheck()
        {
            TimeSpan elapsedTime = TimeSpan.FromMilliseconds(IdleTimeFinder.GetIdleTime());

            if (elapsedTime.TotalMilliseconds < _msTrigger)
            {
                ActivityOccured?.Invoke();
            }
        }
Ejemplo n.º 6
0
        public static bool IsUsing()
        {
            var idleTime = IdleTimeFinder.GetIdleTime();

            if (idleTime.TotalSeconds > 30)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 7
0
 static void Main(string[] args)
 {
     while (true)
     {
         long x = IdleTimeFinder.GetLastInputTime();
         while (x == IdleTimeFinder.GetLastInputTime())
         {
         }
         Console.WriteLine("You have interacted with the device");
     }
 }
Ejemplo n.º 8
0
        private void InterceptMouse_OnMouseLeftButtonDown(object sender, MouseEventArgs e)
        {
            Logger.Info($"Mouse Button Pressed : {e.Button}");
            if (e.Button == MouseButtons.Left)
            {
                Logger.Info($" Location :  {e.X} ,  {e.Y} clicked after {IdleTimeFinder.GetIdleTime()} minutes");
                if (this.FollowMouse)
                {
                    this.CurrentScreen = Screen.FromPoint(new Point(e.X, e.Y));
                    var splashScreen = new TimedSpalshScreen(this.CurrentScreen.WorkingArea, 0.7, Dispatcher.CurrentDispatcher);
                    splashScreen.ShowSplashScreen("Counting down", 10000);
                    this.FollowMouse = false;
                }

                if (this.addingImageClixSenseFind)
                {
                    this.screenShotsManager.AddToFindImages(e, Settings.Default.ClickSenseFindDir);
                    this.addingImageClixSenseFind = false;
                }

                if (this.addingImageClixSenseClose)
                {
                    this.screenShotsManager.AddToFindImages(e, Settings.Default.ClickSenseCloseDir);
                    this.addingImageClixSenseClose = false;
                }

                if (this.addingImageNemoFind)
                {
                    this.screenShotsManager.AddToFindImages(e, Settings.Default.NemoFindDir);
                    this.addingImageNemoFind = false;
                }

                if (this.addingImageNemoDot)
                {
                    this.screenShotsManager.AddToFindImages(e, Settings.Default.NemoDotDir);
                    this.addingImageNemoDot = false;
                }

                if (this.addingImageNemoClose)
                {
                    this.screenShotsManager.AddToFindImages(e, Settings.Default.NemoCloseDir);
                    this.addingImageNemoClose = false;
                }

                var senseAdProcessor = this.clixSenseAdProcessor;

                if (senseAdProcessor != null)
                {
                    senseAdProcessor?.SaveSenseCatImageToDb(e);
                    senseAdProcessor.CaptureCatImage = false;
                    Logger.Info($" {nameof(senseAdProcessor.CaptureCatImage)} : {senseAdProcessor.CaptureCatImage}");
                }
            }
        }
Ejemplo n.º 9
0
        public static bool IsIdle() //In minutes
        {
            TimeSpan idleTime = TimeSpan.FromMilliseconds(IdleTimeFinder.GetIdleTime());

            TimeSpan timeUntilIdle = TimeSpan.FromMinutes(minutesIdle);

            if (TimeSpan.Compare(idleTime, timeUntilIdle) >= 0)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 10
0
 static void Main()
 {
     MessageBox.Show("AutoSleep starting...");                              // Dialog to show that program is running
     while (true)                                                           // infinite loop to ensure progrma is running despite wakingup from sleep
     {
         if (IdleTimeFinder.GetIdleTime() > 600000)                         // Check if 15 minutes have passed
         {
             Application.SetSuspendState(PowerState.Hibernate, true, true); // Sleep
             MessageBox.Show("AutoSleep starting...");                      // Dialog to show that program is running
         }
         Thread.Sleep(1000);                                                // (Power optimization) Makes the program wait 1 second before refreshing, prevents overconsumption of CPU power
         //takes about 20% of CPU if constantly checking for idle time (while loop)
     }
 }
Ejemplo n.º 11
0
        public void GetLastInputTime_Succeeds()
        {
            //arrange
            uint lastInputTicks;

            //act
            lastInputTicks = IdleTimeFinder.GetLastInputTime();
            long     lastInputMs  = Environment.TickCount - lastInputTicks;
            TimeSpan idleTimeSpan = TimeSpan.FromMilliseconds(lastInputMs);

            //assert
            //will fail if you were using the kb/mouse actively during test
            //what can I say it's a kvicky
            Assert.IsTrue(idleTimeSpan.TotalMilliseconds > 0);
        }
Ejemplo n.º 12
0
        static void Main()
        {
            // Initialize variabales
            int  sleepTime     = 10 * 60 * 1000; // 10 minutes
            bool displayed     = false;          // for warning/alert message
            long LastInputTime = IdleTimeFinder.GetLastInputTime();
            // DateTime StartupTime = DateTime.Now; // Else would be undefined

            SoundPlayer alertSound = new SoundPlayer(@"C:\Users\Tze Zhao\Desktop\C#\AutoSleep\Google_event_notification_tone.wav"); //Initiate Sound player

            AutoClosingMessageBox.Show("AutoSleep starting", "AutoSleep.exe", 5000);                                                // Dialog to show that program is running

            while (true)                                                                                                            // infinite loop to ensure program is running despite waking up from sleep
            {
                // To display warning message
                if (IdleTimeFinder.GetIdleTime() > sleepTime - 60000) // Check if there is one minute left before shutdown
                {
                    if (displayed)
                    {
                        if (IdleTimeFinder.GetLastInputTime() != LastInputTime) // means that user has interacted with device
                        {
                            LastInputTime = IdleTimeFinder.GetLastInputTime();  // update last interacted time
                            displayed     = false;                              // computer to display again the next time device is going to sleep
                        }
                    }
                    else
                    {
                        alertSound.Play();                                                             // play alert sound
                        AutoClosingMessageBox.Show("Going to sleep in 1 min", "AutoSleep.exe", 30000); // alert user that computer is going to sleep
                        displayed = true;                                                              // computer has displayed
                    }
                }


                // To put PC to sleep

                //&& (StartupTime.AddMinutes(sleepTime / 60000) > DateTime.Now

                if (IdleTimeFinder.GetIdleTime() > sleepTime)                                // Check if 10 minutes have passed since last user interaction //and waking up from sleep
                {
                    Application.SetSuspendState(PowerState.Suspend, true, true);             // Sleep
                    AutoClosingMessageBox.Show("AutoSleep starting", "AutoSleep.exe", 5000); // Dialog to show that program is running after waking up
                    //StartupTime = DateTime.Now;
                }
                Thread.Sleep(1000); // (Power optimization) Makes the program wait 1 second before refreshing, prevents overconsumption of CPU power
                //takes about 20% of CPU if constantly checking for idle time (while loop)
            }
        }
Ejemplo n.º 13
0
 public void KeepDisplayOn(bool keepScreenWake, bool mimicInput)
 {
     m_SetRequiredIsSuccessful = false;
     // Maintain internal assumption
     if (m_LastPulledScreensaverActiveStateIsRefreshed && DateTime.Now - m_LastPulledScreensaverActiveStateRefreshedAt > TimeSpan.FromMinutes(2))
     {
         PullSystemSettings();
         if (m_ShouldSetScreenSaverOnEnd == (m_LastPulledScreensaverActiveState != 0))
         {
             DisableScreenSaver();
         }
     }
     // Keep Display On
     if (keepScreenWake)
     {
         RunSetAliveWithKeepDisplay();
     }
     if (!m_SetRequiredIsSuccessful)
     {
         if (keepScreenWake)
         {
             // Reset guard so we won't be ignored
             m_SetRequiredCalledAt = DateTime.MinValue;
         }
         RunSetAliveWithoutKeepDisplay();
     }
     if (mimicInput)
     {
         var lastIdle = IdleTimeFinder.GetIdleTimeMilliseconds();
         Debugger.Log(2, "Info", $"Last idle: {lastIdle}\n");
         if (lastIdle > 10000)
         {
             if (m_Jiggled)
             {
                 Jiggler.Jiggle(-m_LastJiggleMovedDistance, -m_LastJiggleMovedDistance);
             }
             else
             {
                 m_LastJiggleMovedDistance = RandomAtStart.Next(1, 4);
                 Jiggler.Jiggle(m_LastJiggleMovedDistance, m_LastJiggleMovedDistance);
                 m_Jiggled = !m_Jiggled;
             }
             //SendKeys.Send("{NUMLOCK}{NUMLOCK}");
         }
     }
 }
Ejemplo n.º 14
0
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            var idleTime = IdleTimeFinder.GetIdleTime();

            if (idleTime > Settings.Default.IdleTimeInMinutes * 60 * 1000 && Status == ProcessStatus.Running)
            {
                StopCommand.Execute(null);
                if (Status == ProcessStatus.Stopped)
                {
                    var result = MessageBox.Show("The StopScript was executed as ilde time was detected! Do you want to run StartScript?", "Idle time - script executed!", MessageBoxButton.YesNo);
                    if (result == MessageBoxResult.Yes)
                    {
                        StartCommand.Execute(null);
                    }
                }
            }
        }
Ejemplo n.º 15
0
        public async Task Execute(IJobExecutionContext context)
        {
            if (InputIdleLockHelper.Instance.LockDisable)
            {
                return;
            }

            if (!InputIdleLockHelper.Instance.CheckInputIdleTime)
            {
                return;
            }

            DateTime dateTime;
            long     ticks = IdleTimeFinder.GetLastInputTime(out dateTime);

            dateTime = dateTime.AddMinutes(InputIdleLockHelper.Instance.Minute);

            if (dateTime < DateTime.Now)
            {
                InteropHelper.LockWorkStation();
            }
        }
Ejemplo n.º 16
0
        void idle_Tick(object sender, EventArgs e)
        {
            var idleTime = IdleTimeFinder.GetIdleTime();

            if (idleTime > maxIdleTime)
            {
                ShowOnTop();

                String str          = String.Format("You have been idle for more than {0} minutes.", maxIdleTime / 60000);
                var    timeOnDialog = DateTime.Now.TimeOfDay;
                idleTicker.Stop();
                MessageBox.Show(str, "You have been idle!", MessageBoxButtons.OK);

                var currTime      = DateTime.Now.TimeOfDay;
                var diff          = currTime - timeOnDialog;
                var totalIdleTime = idleTime + diff.TotalMilliseconds;

                String       remStr     = String.Format("Subtract {0} minutes from all running timers?", totalIdleTime / 60000);
                DialogResult timeResult = MessageBox.Show(remStr, "Subtract time?", MessageBoxButtons.YesNo);

                if (timeResult == DialogResult.Yes)
                {
                    // subtract from all running timers
                    foreach (IssueControl issue in this.issueControls)
                    {
                        issue.WatchTimer.SubtractWhenRunning(totalIdleTime);
                        issue.UpdateOutput();
                    }

                    backupTimer.SubtractWhenRunning(totalIdleTime);
                    UpdateBackupTime();
                }

                idleTicker.Start();
            }
        }
Ejemplo n.º 17
0
 public static TimeSpan Do()
 {
     return(IdleTimeFinder.getTimeSpent(IdleTimeFinder.GetIdleTime()));
 }
Ejemplo n.º 18
0
        public static byte[] idleTime(Command command)
        {
            TimeSpan time = TimeSpan.FromMilliseconds(IdleTimeFinder.GetIdleTime());

            return(Util.Serialization.serialize(time));
        }
Ejemplo n.º 19
0
        public static int GetIdleTime()
        {
            var idleTime = IdleTimeFinder.GetIdleTime();

            return((int)idleTime.TotalSeconds);
        }
Ejemplo n.º 20
0
        private void _timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            var timeLeft = AppSettings.Settings.IdleTimeLimit - TimeSpan.FromMilliseconds(IdleTimeFinder.GetIdleTime());

            if (timeLeft.Seconds > 0 && timeLeft.Seconds <= 3)
            {
                Notifier.ShowInformation($"You will be loged out in: { timeLeft.Seconds }!");
            }
            else if (timeLeft.Seconds <= 0)
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    Logout();
                });
            }
        }