Esempio n. 1
0
        /**
         * Main method. Initializes all input managers and starts them.
         * Then, executes the start-up script (right now it just goes
         * to Earth. To make a better one, look at the Extensibility section
         * in TravelCommand.cs)
         * 
         * Author: Ross Kahn
         **/
        public static void Main()
        {

            KeyboardMouseManager keymanager = new KeyboardMouseManager();
            keymanager.start();

            KinectManager kinectManager = new KinectManager();
            SpeechManager speechManager = new SpeechManager();

            kinectManager.Initialize();

            if (KinectManager.isConnected())
            {
                // Start the speech manager with the Kinect microphone array
                speechManager.Initialize(kinectManager.getSensor());
            }
            else
            {
                // Start the speech manager with the default system microphone because
                // no kinect was detected
                speechManager.Initialize();
            }

            // Start-up script. Works just like a regular travel command
            TravelCommand command = new TravelCommand(Constants.PLANET.EARTH);
            doCommand(command);

            // Keeps the application running. Since this program is event-driven,
            // there needs to be a non-blocking main loop as the program waits
            // for events to come in. That's what Application.Run() does
            try
            {
               Application.Run();  
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace);
            }
      
        }
        /**
         * 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);         
        }