Esempio n. 1
0
        // Create a simple handler for the SpeechRecognized event.
        void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            if (Preference.ActiveMode == Preference.SUPPORTED_MODES.Mouse)
            {
                if (e.Result != null)
                {
                    if (e.Result.Text.CompareTo("zoom in") == 0)
                    {
                        KeyboardController.processGlobeAction("zoom in");
                    }
                    else if (e.Result.Text.CompareTo("zoom out") == 0)
                    {
                        KeyboardController.processGlobeAction("zoom out");
                    }
                    else if (e.Result.Text.CompareTo("capture") == 0)
                    {
                        KeyboardController.processGlobeAction("capture");
                    }
                    else if (e.Result.Text.CompareTo("remove") == 0)
                    {
                        KeyboardController.processGlobeAction("remove");
                    }
                    else if (e.Result.Text.CompareTo("goto Germany") == 0)
                    {
                        KeyboardController.processGlobeAction("Germany");
                    }
                }
            }

            else if (Preference.ActiveMode == Preference.SUPPORTED_MODES.Vjoy_Controller)
            {
                if (e.Result.Text == "give me guns")
                {
                    context.VJOY.PressButton3(action_down);
                    context.VJOY.PressButton3(action_up);
                }


                if (e.Result.Text == "give me rockets")
                {
                    context.VJOY.PressButton4(action_down);
                    context.VJOY.PressButton4(action_up);
                }

                if (e.Result.Text == "open fire")
                {
                    context.VJOY.PressButton1(action_down);
                }

                if (e.Result.Text == "enough")
                {
                    KeyboardController.simulateButton(WindowsInput.VirtualKeyCode.UP, action_up);
                    KeyboardController.simulateButton(WindowsInput.VirtualKeyCode.DOWN, action_up);
                    KeyboardController.simulateButton(WindowsInput.VirtualKeyCode.LEFT, action_up);
                    KeyboardController.simulateButton(WindowsInput.VirtualKeyCode.RIGHT, action_up);

                    context.VJOY.operatePOV(0xFFFFFFFF);
                    context.VJOY.PressButton1(action_up);
                }



                if (e.Result.Text == "go higher")
                {
                    keyboardController.simulatePressWithTimer(WindowsInput.VirtualKeyCode.UP, duration);
                    //KeyboardController.simulateButton(WindowsInput.VirtualKeyCode.UP, action_down);
                }

                if (e.Result.Text == "go lower")
                {
                    keyboardController.simulatePressWithTimer(WindowsInput.VirtualKeyCode.DOWN, duration);
                }

                if (e.Result.Text == "bank left")
                {
                    keyboardController.simulatePressWithTimer(WindowsInput.VirtualKeyCode.LEFT, duration);
                }


                if (e.Result.Text == "bank right")
                {
                    keyboardController.simulatePressWithTimer(WindowsInput.VirtualKeyCode.RIGHT, duration);
                }
            }


            context.logmMssage("Speech recognized: " + e.Result.Text);
        }
        public void decodeAction(String json)
        {
            try
            {
                dynamic dynamicObject = serializer.Deserialize <dynamic>(json);

                if (dynamicObject["type"] == DataType.ACCELEROMETER.ToString())
                {
                    Dictionary <String, object> values = dynamicObject["values"];
                    double x, y, z;

                    x = double.Parse(values["x"].ToString());
                    y = double.Parse(values["y"].ToString());
                    z = double.Parse(values["z"].ToString());

                    MouseController.Move((int)x, (int)y);
                }


                if (dynamicObject["type"] == DataType.GYRO.ToString())
                {
                    Dictionary <String, object> values = dynamicObject["values"];
                    double x, y, z;

                    x = double.Parse(values["x"].ToString());
                    y = double.Parse(values["y"].ToString());
                    z = double.Parse(values["z"].ToString());

                    if (Preference.InvertAxis)
                    {
                        double temp = z;
                        z = y;
                        y = -1 * temp;
                    }

                    if (Preference.ActiveMode == Preference.SUPPORTED_MODES.Mouse)
                    {
                        x = x * Preference.MOUSE_SPEED;
                        y = y * Preference.MOUSE_SPEED;
                        z = z * Preference.MOUSE_SPEED;


                        if (Preference.InvertY)
                        {
                            y = y * -1;
                        }

                        MouseController.Move((int)z, (int)y);
                    }
                    else if (Preference.ActiveMode == Preference.SUPPORTED_MODES.Keyboard)
                    {
                        KeyboardController.PerformMovement((int)z, (int)y);
                    }
                    else if (Preference.ActiveMode == Preference.SUPPORTED_MODES.Vjoy_Controller)
                    {
                        context.VJOY.OperateJoyStick(z, y);
                    }
                }

                if (dynamicObject["type"] == DataType.SPEECH.ToString())
                {
                    String text = dynamicObject["values"];
                    KeyboardController.ProcessSpeech(text.ToLower());
                }

                if (dynamicObject["type"] == DataType.DPAD.ToString())
                {
                    Dictionary <String, object> values = dynamicObject["values"];
                    //uint val = 0xFFFFFFFF;
                    int val = -1;
                    val = int.Parse(values["v"].ToString());

                    if (Preference.ActiveMode == Preference.SUPPORTED_MODES.Vjoy_Controller)
                    {
                        if (val < 0)
                        {
                            context.VJOY.operatePOV(0xFFFFFFFF);
                        }
                        else
                        {
                            context.VJOY.operatePOV(Convert.ToUInt32(val));
                        }
                    }
                }


                if (dynamicObject["type"] == DataType.SCROLL.ToString())
                {
                    Dictionary <String, object> values = dynamicObject["values"];
                    double x, y, z;

                    x = double.Parse(values["x"].ToString());
                    y = double.Parse(values["y"].ToString());
                    z = double.Parse(values["z"].ToString());

                    int scroll = (int)(-1 * y * Preference.MOUSE_SPEED);

                    MouseController.Scroll(scroll);
                }
                if (dynamicObject["type"] == DataType.SHORTCUT.ToString())
                {
                    String text = dynamicObject["values"];
                    KeyboardController.ProcessShortCuts(text.ToLower());
                }

                if (dynamicObject["type"] == DataType.KEYPAD.ToString())
                {
                    String text = dynamicObject["values"];
                    KeyboardController.processGlobeAction(text);
                    //KeyboardController.ProcessShortCuts(text.ToLower());
                }


                if (dynamicObject["type"] == DataType.TOUCH.ToString())
                {
                    String action = dynamicObject["values"];
                    String data   = dynamicObject["id"];

                    if (Preference.ActiveMode == Preference.SUPPORTED_MODES.Mouse)
                    {
                        if (action == "DOWN")
                        {
                            if (dynamicObject["id"] == "L")
                            {
                                MouseController.LeftDown();
                            }
                            else if (dynamicObject["id"] == "R")
                            {
                                MouseController.RightDown();
                            }
                        }

                        else if (action == "UP")
                        {
                            if (dynamicObject["id"] == "L")
                            {
                                MouseController.LeftUp();
                            }
                            else if (dynamicObject["id"] == "R")
                            {
                                MouseController.RightUp();
                            }
                        }
                        if (data == "LEFT")
                        {
                            KeyboardController.simulateButton(VirtualKeyCode.LEFT, action);
                        }

                        else if (data == "RIGHT")
                        {
                            KeyboardController.simulateButton(VirtualKeyCode.RIGHT, action);
                        }
                    }


                    else if (Preference.ActiveMode == Preference.SUPPORTED_MODES.Keyboard)
                    {
                        if (data == "L")
                        {
                            KeyboardController.simulateButton(VirtualKeyCode.RETURN, action);
                        }
                        else if (data == "R")
                        {
                            KeyboardController.simulateButton(VirtualKeyCode.ESCAPE, action);
                        }
                    }


                    else if (Preference.ActiveMode == Preference.SUPPORTED_MODES.Vjoy_Controller)
                    {
                        if (dynamicObject["id"] == "L")
                        {
                            context.VJOY.PressButton1(action);
                        }
                        else if (dynamicObject["id"] == "R")
                        {
                            context.VJOY.PressButton2(action);
                        }

                        if (data == "LEFT")
                        {
                            KeyboardController.simulateButton(VirtualKeyCode.LEFT, action);
                        }

                        else if (data == "RIGHT")
                        {
                            KeyboardController.simulateButton(VirtualKeyCode.RIGHT, action);
                        }
                    }
                }
            }

            catch (Exception e)
            {
                Console.Out.WriteLine(e.StackTrace);
            }
        }
Esempio n. 3
0
 public SpeechHelper(MainWindow ctx)
 {
     context            = ctx;
     keyboardController = new KeyboardController(ctx);
 }