/** * Event handler for speech recognition. Converts the recognized word * into a Command with the word's associated Enum in the grammar dictionaries **/ private void speechRecognized(object sender, SpeechRecognizedEventArgs e) { Command toDo; // Command to generate string text = e.Result.Text; // The word that was recognized // If an Action word was recognized if (actionBindings.Keys.Contains(text)) { // Create new ActionCommand with the ACTION value in actionBindings Constants.ACTION action = actionBindings[text]; toDo = new ActionCommand(action); } // If a Travel word was recognized else if (speechBindings.Keys.Contains(text)) { // Create new TravelCommand with the PLANET value in speechBindings Constants.PLANET travelTo = speechBindings[text]; toDo = new TravelCommand(travelTo); } else { //Console.WriteLine("Speech command not recognized: " + text); return; } Console.WriteLine("Speech Recognized! : " + text); main.doCommand(toDo); }
/** * The event handler for any key being pressed down. That includes simulated * key presses. **/ private void keyboardHook_KeyDown(object sender, KeyEventArgs e) { //Console.WriteLine("(KMM) KeyDown Event: " + e.KeyCode); // Celestia's zoom in and zoom out key // TODO: This should probably use ZoomCommands if (e.KeyCode == Constants.ZOOMIN_KEY || e.KeyCode == Constants.ZOOMOUT_KEY) { return; } Command toDo; // Command to execute if(actionBindings.Keys.Contains(e.KeyCode)) { // Extract the ACTION enum for this key code using actionBindings Constants.ACTION action = actionBindings[e.KeyCode]; // Construct a new ActionCommand using the ACTION enum as a parameter toDo = new ActionCommand(action); } else if (travelBindings.Keys.Contains(e.KeyCode)) { // Extract the PLANET enum for this key code using travelBindings Constants.PLANET travelTo = travelBindings[e.KeyCode]; // Construct a new TravelCommand using the PLANET enum as a parameter toDo = new TravelCommand(travelTo); } else { // Have Celestia print out a message Console.WriteLine("(KeyboardMouseManager.cs) Command not specified for key " + e.KeyCode); return; } // Send the command to be executed main.doCommand(toDo); }