private void CheckForKeys() { while (checkForKeys) { //sleeping for while, this will reduce load on cpu Thread.Sleep(10); foreach (Keys key in Enum.GetValues(typeof(Keys))) { // if key is pressed if (((GetAsyncKeyState(key) & (1 << 15)) != 0)) { // zoom in if (key == Keys.F6) { BeginInvoke(new MethodInvoker(delegate { if (mConfiguration.ZoomFactor < 10f) { mConfiguration.ZoomFactor++; mMainForm.label_ZoomFaktor.Text = mConfiguration.ZoomFactor.ToString(); } })); Thread.Sleep(500); } // zoom out if (key == Keys.F5) { BeginInvoke(new MethodInvoker(delegate { if (mConfiguration.ZoomFactor > 1f) { mConfiguration.ZoomFactor--; mMainForm.label_ZoomFaktor.Text = mConfiguration.ZoomFactor.ToString(); } })); Thread.Sleep(500); } // toggle fullscreen if (key == Keys.Multiply) { if (IsNormal == true) { IsNormal = false; BeginInvoke(new MethodInvoker(delegate { WindowState = FormWindowState.Maximized; fullScreen = true; })); Thread.Sleep(500); } else if (IsNormal == false) { IsNormal = true; BeginInvoke(new MethodInvoker(delegate { WindowState = FormWindowState.Normal; fullScreen = false; })); Thread.Sleep(500); } } if (key == Keys.F4) { if (freeze == false) { freeze = true; Thread.Sleep(500); } else if (freeze == true) { freeze = false; Thread.Sleep(500); } } if (key == Keys.F2) { if (wAIOn == false) { // checkForKeys = false; BeginInvoke(new MethodInvoker(delegate { // WhereAmI wAI = new WhereAmI(wWhereAmIPoint, mConfiguration); //wAI.Show(); temp = mConfiguration.ZoomFactor; mConfiguration.ZoomFactor = 1; if (mConfiguration.invertColors == true) { mConfiguration.invertColors = false; tempString = "invertColors"; } else if (mConfiguration.normal == true) { mConfiguration.normal = false; tempString = "normal"; } else if (mConfiguration.achromatomaly == true) { mConfiguration.achromatomaly = false; tempString = "achromatomaly"; } else if (mConfiguration.achromatopsia == true) { mConfiguration.achromatopsia = false; tempString = "achromatopsia"; } else if (mConfiguration.deuteranopia == true) { mConfiguration.deuteranopia = false; tempString = "deuteranopia"; } else if (mConfiguration.deuteranomaly == true) { mConfiguration.deuteranomaly = false; tempString = "deuteranomaly"; } else if (mConfiguration.protanomaly == true) { mConfiguration.protanomaly = false; tempString = "protanomaly"; } else if (mConfiguration.protanopia == true) { mConfiguration.protanopia = false; tempString = "protanopia"; } else if (mConfiguration.tritanomaly == true) { mConfiguration.tritanomaly = false; tempString = "tritanomaly"; } else if (mConfiguration.tritanopia == true) { mConfiguration.tritanopia = false; tempString = "tritanopia"; } mConfiguration.normal = true; })); Thread.Sleep(500); wAIOn = true; count = 0; getLastMousePosition = true; } else if (wAIOn == true) { wAIOn = false; BeginInvoke(new MethodInvoker(delegate { List <Form> forms = new List <Form>(); foreach (Form f in Application.OpenForms) { if (f.Name == "WhereAmI") { forms.Add(f); } } // Now let's close opened myForm instances from aother thread if (forms.Count > 0) { foreach (Form f in forms) { f.Close(); } } mConfiguration.normal = false; mConfiguration.ZoomFactor = temp; if (tempString == "invertColors") { mConfiguration.invertColors = true; } else if (tempString == "normal") { mConfiguration.normal = true; } else if (tempString == "achromatomaly") { mConfiguration.achromatomaly = true; } else if (tempString == "achromatopsia") { mConfiguration.achromatopsia = true; } else if (tempString == "deuteranopia") { mConfiguration.deuteranopia = true; } else if (tempString == "deuteranomaly") { mConfiguration.deuteranomaly = true; } else if (tempString == "protanomaly") { mConfiguration.protanomaly = true; } else if (tempString == "protanopia") { mConfiguration.protanopia = true; } else if (tempString == "tritanomaly") { mConfiguration.tritanomaly = true; } else if (tempString == "tritanopia") { mConfiguration.tritanopia = true; } })); Thread.Sleep(500); } } if (key == Keys.F3) { BeginInvoke(new MethodInvoker(delegate { mMainForm.Location = Cursor.Position; NativeMethods.SetWindowPos(mMainForm.Handle, 0, 0, 0, 0, 0, 0x0002 | 0x0001); NativeMethods.ShowWindow(mMainForm.Handle, 5); NativeMethods.SetForegroundWindow(mMainForm.Handle); NativeMethods.SetFocus(mMainForm.Handle); mMainForm.Left = (int)Cursor.Position.X - mMainForm.Width / 2; mMainForm.Top = (int)Cursor.Position.Y - mMainForm.Height / 2; if (mMainForm.Left < 0) { mMainForm.Left = 0; } if (mMainForm.Left > Screen.PrimaryScreen.Bounds.Width - mMainForm.Width) { mMainForm.Left = Screen.PrimaryScreen.Bounds.Width - mMainForm.Width; } if (mMainForm.Top < 0) { mMainForm.Top = 0; } if (mMainForm.Top > Screen.PrimaryScreen.Bounds.Height - mMainForm.Height) { mMainForm.Top = Screen.PrimaryScreen.Bounds.Height - mMainForm.Height; } mMainForm.WindowState = FormWindowState.Normal; })); Thread.Sleep(500); } if (key == Keys.F9) { if (mConfiguration.invertColors == true) { tempF9 = "invertColors"; BeginInvoke(new MethodInvoker(delegate { mConfiguration.normal = true; mConfiguration.invertColors = false; mConfiguration.achromatomaly = false; mConfiguration.achromatopsia = false; mConfiguration.deuteranopia = false; mConfiguration.deuteranomaly = false; mConfiguration.protanomaly = false; mConfiguration.protanopia = false; mConfiguration.tritanomaly = false; mConfiguration.tritanopia = false; })); Thread.Sleep(500); } else if (mConfiguration.invertColors == false) { BeginInvoke(new MethodInvoker(delegate { mConfiguration.normal = false; mConfiguration.invertColors = true; mConfiguration.achromatomaly = false; mConfiguration.achromatopsia = false; mConfiguration.deuteranopia = false; mConfiguration.deuteranomaly = false; mConfiguration.protanomaly = false; mConfiguration.protanopia = false; mConfiguration.tritanomaly = false; mConfiguration.tritanopia = false; })); Thread.Sleep(500); } } //Windows Magnification Size if (key == Keys.F8) { if (Screen.PrimaryScreen.Bounds.Height - mConfiguration.MagnifierHeight >= 10 && Screen.PrimaryScreen.Bounds.Width - mConfiguration.MagnifierWidth >= 10) { if (mConfiguration.MagnifierHeight <= (Screen.PrimaryScreen.Bounds.Height / 10) * 9 && mConfiguration.MagnifierWidth <= Screen.PrimaryScreen.Bounds.Width - 30) { BeginInvoke(new MethodInvoker(delegate { mConfiguration.MagnifierHeight += 10; mConfiguration.MagnifierWidth += 10; })); Thread.Sleep(500); } } } if (key == Keys.F7) { if (mConfiguration.MagnifierHeight > (Screen.PrimaryScreen.Bounds.Height / 10) && mConfiguration.MagnifierWidth > (Screen.PrimaryScreen.Bounds.Width / 10)) { if (mConfiguration.MagnifierHeight > Screen.PrimaryScreen.Bounds.Height / 9 && mConfiguration.MagnifierWidth != Screen.PrimaryScreen.Bounds.Width / 9) { BeginInvoke(new MethodInvoker(delegate { mConfiguration.MagnifierHeight -= 10; mConfiguration.MagnifierWidth -= 10; })); Thread.Sleep(500); } } } if (key == Keys.Escape) { BeginInvoke(new MethodInvoker(delegate { NativeMethods.MagShowSystemCursor(true); List <Form> forms = new List <Form>(); foreach (Form f in Application.OpenForms) { if (f.Name == "WhereAmI") { forms.Add(f); } } // Now let's close opened myForm instances from aother thread if (forms.Count > 0) { foreach (Form f in forms) { f.Close(); } } this.Close(); if (IsBothEyeAndHead) { mgBothEyeAndHead.Dispose(); } if (IsBothEye) { mgBothEye.Dispose(); } if (IsLeftEyeAndHead) { mgLeftEyeAndHead.Dispose(); } if (IsLeftEye) { mgLeftEye.Dispose(); } if (IsRightEyeAndHead) { mgRightEyeAndHead.Dispose(); } if (IsRightEye) { mgRightEye.Dispose(); } if (IsJustHeadAndHead) { mgJustHead.Dispose(); } checkForKeys = false; //mgBothEye.close = true; mMainForm.TobiiCalibration_button.Enabled = true; mMainForm.MagniferUsingMouse_button.Enabled = true; mMainForm.FullscreenMaginfierEye_Button.Enabled = true; mMainForm.MaginfierEye_Button.Enabled = true; mMainForm.FullScreenMouse_Button.Enabled = true; mMainForm.Evaluation_button.Enabled = true; })); Thread.Sleep(500); } } } } }
private void CheckForKeys() { while (checkForKeys) { //sleeping for while, this will reduce load on cpu Thread.Sleep(10); foreach (Keys key in Enum.GetValues(typeof(Keys))) { // if key is pressed if (((GetAsyncKeyState(key) & (1 << 15)) != 0)) { // zoom in if (key == Keys.Add) { BeginInvoke(new MethodInvoker(delegate { if (mConfiguration.ZoomFactor < 10f) { mConfiguration.ZoomFactor++; mMainForm.label_ZoomFaktor.Text = mConfiguration.ZoomFactor.ToString(); } })); Thread.Sleep(500); } // zoom out if (key == Keys.Subtract) { BeginInvoke(new MethodInvoker(delegate { if (mConfiguration.ZoomFactor > 1f) { mConfiguration.ZoomFactor--; mMainForm.label_ZoomFaktor.Text = mConfiguration.ZoomFactor.ToString(); } })); Thread.Sleep(500); } // toggle fullscreen if (key == Keys.Multiply) { if (IsNormal == true) { IsNormal = false; BeginInvoke(new MethodInvoker(delegate { WindowState = FormWindowState.Maximized; })); Thread.Sleep(500); } else if (IsNormal == false) { IsNormal = true; BeginInvoke(new MethodInvoker(delegate { WindowState = FormWindowState.Normal; })); Thread.Sleep(500); } } if (key == Keys.F2) { if (wAIOn == false) { // checkForKeys = false; wAIOn = true; BeginInvoke(new MethodInvoker(delegate { WhereAmI wAI = new WhereAmI(wWhereAmIPoint, mConfiguration); wAI.Show(); temp = mConfiguration.ZoomFactor; mConfiguration.ZoomFactor = 1; if (mConfiguration.invertColors == true) { mConfiguration.invertColors = false; tempString = "invertColors"; } else if (mConfiguration.normal == true) { mConfiguration.normal = false; tempString = "normal"; } else if (mConfiguration.achromatomaly == true) { mConfiguration.achromatomaly = false; tempString = "achromatomaly"; } else if (mConfiguration.achromatopsia == true) { mConfiguration.achromatopsia = false; tempString = "achromatopsia"; } else if (mConfiguration.deuteranopia == true) { mConfiguration.deuteranopia = false; tempString = "deuteranopia"; } else if (mConfiguration.deuteranomaly == true) { mConfiguration.deuteranomaly = false; tempString = "deuteranomaly"; } else if (mConfiguration.protanomaly == true) { mConfiguration.protanomaly = false; tempString = "protanomaly"; } else if (mConfiguration.protanopia == true) { mConfiguration.protanopia = false; tempString = "protanopia"; } else if (mConfiguration.tritanomaly == true) { mConfiguration.tritanomaly = false; tempString = "tritanomaly"; } else if (mConfiguration.tritanopia == true) { mConfiguration.tritanopia = false; tempString = "tritanopia"; } mConfiguration.normal = true; })); Thread.Sleep(500); } else if (wAIOn == true) { wAIOn = false; BeginInvoke(new MethodInvoker(delegate { List <Form> forms = new List <Form>(); foreach (Form f in Application.OpenForms) { if (f.Name == "WhereAmI") { forms.Add(f); } } // Now let's close opened myForm instances from aother thread if (forms.Count > 0) { foreach (Form f in forms) { f.Close(); } } mConfiguration.normal = false; mConfiguration.ZoomFactor = temp; if (tempString == "invertColors") { mConfiguration.invertColors = true; } else if (tempString == "normal") { mConfiguration.normal = true; } else if (tempString == "achromatomaly") { mConfiguration.achromatomaly = true; } else if (tempString == "achromatopsia") { mConfiguration.achromatopsia = true; } else if (tempString == "deuteranopia") { mConfiguration.deuteranopia = true; } else if (tempString == "deuteranomaly") { mConfiguration.deuteranomaly = true; } else if (tempString == "protanomaly") { mConfiguration.protanomaly = true; } else if (tempString == "protanopia") { mConfiguration.protanopia = true; } else if (tempString == "tritanomaly") { mConfiguration.tritanomaly = true; } else if (tempString == "tritanopia") { mConfiguration.tritanopia = true; } })); Thread.Sleep(500); } } if (key == Keys.F3) { BeginInvoke(new MethodInvoker(delegate { mMainForm.Location = this.Location; mMainForm.WindowState = FormWindowState.Normal; })); Thread.Sleep(500); } if (key == Keys.Escape) { BeginInvoke(new MethodInvoker(delegate { NativeMethods.MagShowSystemCursor(true); List <Form> forms = new List <Form>(); foreach (Form f in Application.OpenForms) { if (f.Name == "WhereAmI") { forms.Add(f); } } // Now let's close opened myForm instances from aother thread if (forms.Count > 0) { foreach (Form f in forms) { f.Close(); } } mMainForm.button_BackToMain.Hide(); this.Close(); if (IsBothEyeAndHead) { mgBothEyeAndHead.Dispose(); } if (IsBothEye) { mgBothEye.Dispose(); } if (IsLeftEyeAndHead) { mgLeftEyeAndHead.Dispose(); } if (IsLeftEye) { mgLeftEye.Dispose(); } if (IsRightEyeAndHead) { mgRightEyeAndHead.Dispose(); } if (IsRightEye) { mgRightEye.Dispose(); } if (IsJustHeadAndHead) { mgJustHead.Dispose(); } checkForKeys = false; mMainForm.MagniferUsingMouse_button.Enabled = true; mMainForm.FullscreenMaginfierEye_Button.Enabled = true; mMainForm.MaginfierEye_Button.Enabled = true; mMainForm.FullScreenMouse_Button.Enabled = true; mMainForm.Evaluation_button.Enabled = true; })); Thread.Sleep(500); } } } } }
private void HandleEsc(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Add) { BeginInvoke(new MethodInvoker(delegate { if (mConfiguration.ZoomFactor < 10f) { mConfiguration.ZoomFactor++; mMainForm.label_ZoomFaktor.Text = mConfiguration.ZoomFactor.ToString(); } })); } // zoom out if (e.KeyCode == Keys.Subtract) { BeginInvoke(new MethodInvoker(delegate { if (mConfiguration.ZoomFactor > 1f) { mConfiguration.ZoomFactor--; mMainForm.label_ZoomFaktor.Text = mConfiguration.ZoomFactor.ToString(); } })); } // toggle fullscreen if (e.KeyCode == Keys.Multiply) { if (IsNormal) { IsNormal = false; BeginInvoke(new MethodInvoker(delegate { WindowState = FormWindowState.Maximized; })); } else { IsNormal = true; BeginInvoke(new MethodInvoker(delegate { WindowState = FormWindowState.Normal; })); } } if (e.KeyCode == Keys.Escape) { NativeMethods.MagShowSystemCursor(true); mMainForm.button_BackToMain.Hide(); this.Close(); if (IsBothEyeAndHead) { mgBothEyeAndHead.Dispose(); } if (IsBothEye) { mgBothEye.Dispose(); } if (IsLeftEyeAndHead) { mgLeftEyeAndHead.Dispose(); } if (IsLeftEye) { mgLeftEye.Dispose(); } if (IsRightEyeAndHead) { mgRightEyeAndHead.Dispose(); } if (IsRightEye) { mgRightEye.Dispose(); } if (IsJustHeadAndHead) { mgJustHead.Dispose(); } mMainForm.MagniferUsingMouse_button.Enabled = true; mMainForm.FullscreenMaginfierEye_Button.Enabled = true; mMainForm.MaginfierEye_Button.Enabled = true; mMainForm.FullScreenMouse_Button.Enabled = true; mMainForm.Evaluation_button.Enabled = true; } if (e.KeyCode == Keys.F1) { WhereAmI wAI = new WhereAmI(this, wWhereAmIPoint); this.Hide(); wAI.Show(); } }