// --| Alert and do things according to user settings
        // --| I created this function to avoid code duplication since i am going to use it twice in keyboard press event hook and mouse movement
        public void AlertAndProtect()
        {
            // "Play a sound on detection" is checked so we play our alarm sound file on loop until he clicks "Okay." button on the other warning form
            if (chkBox_Alert.Checked)
            {
                SoundPlayer CustomSound = new SoundPlayer(Properties.Resources.alarm);
                CustomSound.PlayLooping();
            }

            // --| "lock windows on movement detection" is checked so we lock windows
            if (chkBox_Lock.Checked)
            {
                LockWorkStation();
            }

            // --| We stop all our timers and scanners since detection has been made
            ScannerTimer.Stop();
            ScannerTimer.Enabled = false;

            IdleChekTimer.Stop();
            IdleChekTimer.Enabled = false;

            // --| Display our warning form
            Form3 WarningForm = new Form3();

            WarningForm.Show();
        }
        // --| User clicked the "Stop Scanner" button
        // --| Now if the scanner is not running at all we throw an error message
        // --| If the scanner has been working but process was stopped by the button, we throw an info message
        // --| We also stop all scanners
        private void button1_Click_1(object sender, EventArgs e)
        {
            // --| If the "Auto-Start if system is idle" is checked, first we stop that
            if (chkBox_Idle.Checked == true)
            {
                chkBox_Idle.Checked = false;

                IdleChekTimer.Stop();
                IdleChekTimer.Enabled = false;

                isScannerDetected = false;

                // --| Disable radar.GIF animation
                pictureBox2_Scanner.Enabled = false;

                MessageBox.Show("Scanner Stopped", "Scanner has ben stopped.", MessageBoxButtons.OK, MessageBoxIcon.Information);

                return;
            }

            // --| If there is no scanner running, we throw an information
            if (timer2.Enabled == false)
            {
                MessageBox.Show("Scanner not running", "Scanner is not running!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                return;
            }

            // --| We stop the scanners
            ScannerTimer.Stop();
            ScannerTimer.Enabled = false;

            timer2.Stop();
            timer2.Enabled = false;

            isScannerDetected = false;

            // --| Disable radar.GIF animation
            pictureBox2_Scanner.Enabled = false;

            MessageBox.Show("Scanner Stopped", "Scanner has ben stopped.", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        // --| User unchecked device "Keyboard"
        // --| If the Scanner or Auto-start on IDLE scanner is active, we disable them since we cannot run a scanner without having what to detect"
        private void chkBox_Keyboard_CheckedChanged(object sender, EventArgs e)
        {
            if (chkBox_Keyboard.Enabled == false || chckBox_Mouse.Checked == false)
            {
                if (ScannerTimer.Enabled == true || timer2.Enabled == true)
                {
                    // --| We stop all our timers and scanners since detection has been made
                    ScannerTimer.Stop();
                    ScannerTimer.Enabled = false;

                    timer2.Stop();
                    timer2.Enabled = false;

                    // --| Disable radar.GIF animation
                    pictureBox2_Scanner.Enabled = false;

                    MessageBox.Show("Scanner stopped, please select at least one device!", "Scanner Stopped", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                if (IdleChekTimer.Enabled == true)
                {
                    // --| Uncheck our "Auto-Start if system is idle" checkbox
                    chkBox_Idle.Checked = false;

                    // --| Disable radar.GIF animation
                    pictureBox2_Scanner.Enabled = false;

                    IdleChekTimer.Stop();
                    IdleChekTimer.Enabled = false;

                    MessageBox.Show("Scanner stopped, please select at least one device!", "Scanner Stopped", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
            }
        }
        private void chkBox_Idle_CheckedChanged(object sender, EventArgs e)
        {
            if (chkBox_Idle.Checked == true)
            {
                // --| Check if the scanner is running or in process to start and throw a warning message to the user, while automatically unchecking the checkbox since we
                // --| don't want two scanning processes to start at the same time
                if (ScannerTimer.Enabled == true || timer2.Enabled == true)
                {
                    chkBox_Idle.Checked = false;
                    MessageBox.Show("You need to turn off the Scanner first in order to use this setting!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    // --| Enable radar.GIF animation
                    pictureBox2_Scanner.Enabled = true;

                    return;
                }

                // --| If there is no device checked, throw an error
                if (chckBox_Mouse.Checked == false && chkBox_Keyboard.Checked == false)
                {
                    // --| Uncheck our "Auto-Start if system is idle" checkbox
                    chkBox_Idle.Checked = false;

                    MessageBox.Show("Try to select at least one device!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // --| Disable radar.GIF animation
                    pictureBox2_Scanner.Enabled = false;

                    return;
                }

                // --| If scanner is not running or not in process to start then we start it
                else
                {
                    // --| Get value from "Idle Control" Dropdown list
                    IdleIntervalDropdownListCheck();

                    // --| Enable radar.GIF animation
                    pictureBox2_Scanner.Enabled = true;

                    // --| Start searching if system is IDLE
                    IdleChekTimer.Start();
                    IdleChekTimer.Enabled = true;

                    // --| Since we don't want two timers to run at a time, when "Auto-Start if system is idle" is checked
                    // --| we disable "Start Scanner" button and we disable the "Scanner Start Delay" dropdown list
                    btn_StartScanner.Enabled        = false;
                    comboBox_StartSelection.Enabled = false;
                }
            }

            // --| If checkbox is unchecked then we enable "Start Scanner" button and "Scanner Start Delay" dropdown list again
            // --| Also we disable the timer where it checks for system being idle or not
            if (chkBox_Idle.Checked == false)
            {
                btn_StartScanner.Enabled        = true;
                comboBox_StartSelection.Enabled = true;

                // --| Disable radar.GIF animation
                pictureBox2_Scanner.Enabled = false;

                IdleChekTimer.Stop();
                IdleChekTimer.Enabled = false;
            }
        }
        // --| Event for key press from Global Mouse and Keyboard hook
        public void HookKeyDown(object sender, KeyEventArgs e)
        {
            // --| If user presses End KEY while one of the scanners are running, in this way we detect that he knows what key to press
            // --| and we know is the computer admin/owner so we stop the scanners
            if (e.KeyCode == Keys.End)
            {
                if (ScannerTimer.Enabled == true || timer2.Enabled == true)
                {
                    // --| We stop all our timers and scanners since user pressed F2 key so we know he is the owned or the computer
                    ScannerTimer.Stop();
                    ScannerTimer.Enabled = false;

                    timer2.Stop();
                    timer2.Enabled = false;

                    // --| Play a feedback soun so owner knows that program has detected his End shortcut and disabled scanners
                    // --| SOUND TAKEN FOR FREE FROM http://soundjax.com/alarm-1.html
                    SoundPlayer StoppedSound = new SoundPlayer(Properties.Resources.stopped);
                    StoppedSound.Play();
                }

                else if (IdleChekTimer.Enabled == true || chkBox_Idle.Checked == true)
                {
                    // --| Disable idle scanner
                    IdleChekTimer.Stop();
                    IdleChekTimer.Enabled = false;

                    // --| Uncheck "Auto-Start if system is idle" checkbox
                    chkBox_Idle.Checked = false;

                    // --| Re-enable our start scanner button and dropdown list
                    btn_StartScanner.Enabled        = true;
                    comboBox_StartSelection.Enabled = true;

                    // --| Play a feedback soun so owner knows that program has detected his End shortcut and disabled scanners
                    // --| SOUND TAKEN FOR FREE FROM http://soundjax.com/alarm-1.html
                    SoundPlayer StoppedSound = new SoundPlayer(Properties.Resources.stopped);
                    StoppedSound.Play();
                }

                // --| Disable radar.GIF animation
                pictureBox2_Scanner.Enabled = false;

                // --| Disable value for scanner detection
                isScannerDetected = false;

                return;
            }

            // --| If "Keyboard" checkbox is checked then our scanner will detect keypress
            if (chkBox_Keyboard.Checked == true)
            {
                if (ScannerTimer.Enabled == true && timer2.Enabled == false)
                {
                    // --| Our scanner has detected something so we turn it to true value
                    isScannerDetected = true;

                    // --| Do what user selected in settings
                    AlertAndProtect();
                }
            }
        }