private void PressKey(JoystickKeys key) { this.Invoke(new Action(async() => { input.Keyboard.KeyDown(joystick.Map[key].Input); texts[key].BackColor = Color.Green; await Task.Delay(150); texts[key].BackColor = Color.White; input.Keyboard.KeyUp(joystick.Map[key].Input); })); }
private void ActiveBox(JoystickKeys key) { texts[key].Invoke(new Action(() => texts[key].BackColor = Color.Green)); }
private void DesactiveBox(JoystickKeys key) { texts[key].Invoke(new Action(() => texts[key].BackColor = Color.White)); }
// Create a simple handler for the SpeechRecognized event. void sre_SpeechRecognized(object sender, SpeechHypothesizedEventArgs e) { Console.WriteLine("Speech recognized: " + e.Result.Text + " - Precision: " + e.Result.Confidence + " Recognition: " + _RECOGNIZE); if (e.Result.Confidence < 0.1) { return; } var time = new Stopwatch(); time.Start(); // Search for a key mapped on the command var command = joystick.Map.ToList().SingleOrDefault(a => a.Value.Command.Equals(e.Result.Text) && a.Value.Valid); VirtualKeyCode virtualKey = VirtualKeyCode.NONAME; JoystickKeys joystickKey = JoystickKeys.NONE; switch (command.Key) { case JoystickKeys.RECOGNIZE_START: if (!_RECOGNIZE) { _RECOGNIZE = true; AllKeys(block: _RECOGNIZE); } break; case JoystickKeys.RECOGNIZE_STOP: if (_RECOGNIZE) { _RECOGNIZE = false; AllKeys(block: _RECOGNIZE); } break; // Case controllers: case JoystickKeys.STICK: if (_RECOGNIZE) { _STICK = !_STICK; if (_STICK) { ActiveBox(command.Key); } else { ReleaseMoveKeys(false, true, false); DesactiveBox(command.Key); } } break; case JoystickKeys.CAMERA: if (_RECOGNIZE) { _CAMERA = !_CAMERA; if (_CAMERA) { ActiveBox(command.Key); } else { ReleaseMoveKeys(false, false, true); DesactiveBox(command.Key); } } break; case JoystickKeys.HOLD_MOVE: if (_RECOGNIZE) { _HOLD_MOVE = !_HOLD_MOVE; if (_HOLD_MOVE) { ActiveBox(command.Key); } else { ReleaseMoveKeys(true, true, true); DesactiveBox(command.Key); } } break; case JoystickKeys.TRIGGER: if (_RECOGNIZE) { _TRIGGER = !_TRIGGER; if (_TRIGGER) { ActiveBox(command.Key); } else { DesactiveBox(command.Key); ReleaseTriggerKeys(); } } break; // Case moving: case JoystickKeys.LEFT: if (_RECOGNIZE) { ReleaseMoveKeys(true, true, true); if (_STICK) { joystickKey = JoystickKeys.STICK_LEFT; } else if (_CAMERA) { joystickKey = JoystickKeys.CAMERA_LEFT; } else if (_TRIGGER) { joystickKey = JoystickKeys.LB; } else { joystickKey = JoystickKeys.LEFT; } virtualKey = joystick.Map[joystickKey].Input; if (_HOLD_MOVE && !_TRIGGER) { input.Keyboard.KeyDown(virtualKey); ActiveBox(joystickKey); } else if (_HOLD_ACTION && _TRIGGER) { input.Keyboard.KeyDown(virtualKey); ActiveBox(joystickKey); } else { PressKey(joystickKey); } } break; case JoystickKeys.RIGHT: if (_RECOGNIZE) { ReleaseMoveKeys(true, true, true); if (_STICK) { joystickKey = JoystickKeys.STICK_RIGHT; } else if (_CAMERA) { joystickKey = JoystickKeys.CAMERA_RIGHT; } else if (_TRIGGER) { joystickKey = JoystickKeys.RB; } else { joystickKey = JoystickKeys.RIGHT; } virtualKey = joystick.Map[joystickKey].Input; if (_HOLD_MOVE && !_TRIGGER) { input.Keyboard.KeyDown(virtualKey); ActiveBox(joystickKey); } else if (_HOLD_ACTION && _TRIGGER) { input.Keyboard.KeyDown(virtualKey); ActiveBox(joystickKey); } else { PressKey(joystickKey); } } break; case JoystickKeys.UP: if (_RECOGNIZE) { ReleaseMoveKeys(true, true, true); if (_STICK) { joystickKey = JoystickKeys.STICK_UP; virtualKey = joystick.Map[joystickKey].Input; } else if (_CAMERA) { joystickKey = JoystickKeys.CAMERA_UP; virtualKey = joystick.Map[joystickKey].Input; } else { joystickKey = JoystickKeys.UP; virtualKey = joystick.Map[joystickKey].Input; } if (_HOLD_MOVE) { input.Keyboard.KeyDown(virtualKey); ActiveBox(joystickKey); } else { PressKey(joystickKey); } } break; case JoystickKeys.DOWN: if (_RECOGNIZE) { if (_STICK) { joystickKey = JoystickKeys.STICK_DOWN; virtualKey = joystick.Map[joystickKey].Input; } else if (_CAMERA) { joystickKey = JoystickKeys.CAMERA_DOWN; virtualKey = joystick.Map[joystickKey].Input; } else { joystickKey = JoystickKeys.DOWN; virtualKey = joystick.Map[joystickKey].Input; } if (_HOLD_MOVE) { input.Keyboard.KeyDown(virtualKey); ActiveBox(joystickKey); } else { PressKey(joystickKey); } } break; case JoystickKeys.STOP: if (_RECOGNIZE) { ReleaseMoveKeys(true, true, true); ReleaseActionKeys(); ReleaseControlKeys(); ReleaseTriggerKeys(); PressKey(command.Key); } break; // Case action: case JoystickKeys.A: if (_RECOGNIZE) { if (command.Value.CanHold) { _A = !_A; if (_A) { input.Keyboard.KeyDown(command.Value.Input); ActiveBox(command.Key); } else { input.Keyboard.KeyUp(command.Value.Input); DesactiveBox(command.Key); } } else { PressKey(command.Key); } } break; case JoystickKeys.B: if (_RECOGNIZE) { if (command.Value.CanHold) { _B = !_B; if (_B) { input.Keyboard.KeyDown(command.Value.Input); ActiveBox(command.Key); } else { input.Keyboard.KeyUp(command.Value.Input); DesactiveBox(command.Key); } } else { PressKey(command.Key); } } break; case JoystickKeys.X: if (_RECOGNIZE) { if (command.Value.CanHold) { _X = !_X; if (_X) { input.Keyboard.KeyDown(command.Value.Input); ActiveBox(command.Key); } else { input.Keyboard.KeyUp(command.Value.Input); DesactiveBox(command.Key); } texts[command.Key].Invoke(new Action(() => texts[command.Key].BackColor = (_X ? Color.Green : Color.White))); } else { PressKey(command.Key); } } break; case JoystickKeys.Y: if (_RECOGNIZE) { if (command.Value.CanHold) { _Y = !_Y; if (_Y) { input.Keyboard.KeyDown(command.Value.Input); ActiveBox(command.Key); } else { input.Keyboard.KeyUp(command.Value.Input); DesactiveBox(command.Key); } } else { PressKey(command.Key); } } break; // Case menu: case JoystickKeys.START: if (_RECOGNIZE) { PressKey(command.Key); } break; case JoystickKeys.SELECT: if (_RECOGNIZE) { PressKey(command.Key); } break; case JoystickKeys.LOGO: if (_RECOGNIZE) { PressKey(command.Key); _canRecognize = false; Recognize(); try { JogosForm jogosForm = new JogosForm(); var result = jogosForm.ShowDialog(); if (result == DialogResult.Cancel) { var g = LoadJoystick(jogosForm.gameChoosed); InitializeRecogition(g); } }catch (Exception ex) { _canRecognize = true; Recognize(); Console.WriteLine(ex.Message); } } break; default: break; } time.Stop(); var timeElapsed = time.ElapsedMilliseconds; ReportGenerator.Save(new Record { Game = joystick.Game.Name, Command = e.Result.Text, Precision = e.Result.Confidence, TimeToAction = timeElapsed }); }