// --| Timer2 think // --| If ScannerTimer is not enabled, we enable it, we stop timer2 aswell // --| We get the current position of the cursor in X and Y axis private void timer2_Tick(object sender, EventArgs e) { if (ScannerTimer.Enabled != true) { CursorPositionX = Cursor.Position.X; CursorPositionY = Cursor.Position.Y; ScannerTimer.Start(); ScannerTimer.Enabled = true; timer2.Stop(); timer2.Enabled = false; } }
// --| 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; } } } } }