コード例 #1
0
        public void removeCommand(String s)
        {
            // Remove from list view
            foreach (ListViewItem i in lvCommands.Items)
            {
                if (i.Text == s)
                {
                    lvCommands.Items.Remove(i);
                }
            }

            // Remove from List CVO commands
            //foreach (CommandVO cvo in commands)
            int selectedIndex = -1;

            for (int i = 0; i < commands.Count; i++)
            {
                CommandVO cvo    = commands[i];
                string    speech = cvo.speech;
                if (speech == s)
                {
                    selectedIndex = i;
                    //commands.Remove(cvo);
                }
            }
            if (selectedIndex > -1)
            {
                commands.RemoveAt(selectedIndex);
            }

            ui.profileHandler.save();
        }
コード例 #2
0
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        public void processCommand(String command)
        {
            //ui.log("CommandHandler.processCommand(s:" + command + ")");

            CommandVO cvo = ui.grammarHandler.getCommandVO(command);

            String commandType = "";

            if (cvo.autoType.Length > 0)
            {
                commandType = "auto type";
            }
            else if (cvo.clipboard.Length > 0)
            {
                commandType = "clipboard";
            }
            else if (cvo.multiKey.Length > 0)
            {
                commandType = "multi key";
            }
            else
            {
                commandType = "application";
            }

            Console.WriteLine("Command Type = " + commandType);



            switch (commandType)
            {
            case "clipboard":
                new ProcessClipboardCommand(cvo);
                break;

                /*
                 * case "move left":
                 *  SendKeys.Send("{LEFT}");
                 *  break;
                 * case "move right":
                 *  SendKeys.Send("{RIGHT}");
                 *  break;
                 * case "move up":
                 *  SendKeys.Send("{UP}");
                 *  break;
                 * case "move down":
                 *  SendKeys.Send("{DOWN}");
                 *  break;
                 * case "press alt":
                 *  SendKeys.Send("%");
                 *  break;
                 * case "press f":
                 *  SendKeys.Send("f");
                 *  break;
                 */
            }
        }
コード例 #3
0
        public CommandVO getCommandVO(String speech)
        {
            CommandVO cvo = null;

            foreach (CommandVO c in commands)
            {
                if (speech == c.speech)
                {
                    cvo = c;
                }
            }

            return(cvo);
        }
コード例 #4
0
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        public ProcessClipboardCommand(CommandVO c)
        {
            cvo = c;
            Clipboard.SetText(cvo.clipboard);
            Console.WriteLine("cvo.clipboard = " + cvo.clipboard);
            Console.WriteLine("cvo.clipboardAutoPaste = " + cvo.clipboardAutoPaste.ToString());

            IntPtr handle = GetActiveWindow();

            //int iHandle = FindWindow(null, "Untitled - Notepad");
            //SetForegroundWindow(iHandle);

            if (cvo.clipboardAutoPaste)
            {
                //SendKeys.Send(cvo.clipboard);
                SendKeys.Send("^{v}");
            }
            //SendKeys.Send("{ENTER}");
        }
コード例 #5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            ui.log("FormClipboard.btnSave_Click()");

            if (commandRejected)
            {
                return;
            }



            if (tbSpeech.Text.Length == 0)
            {
                MessageBox.Show("Please enter a speech command!");
                this.ActiveControl = tbSpeech;
                return;
            }

            //MessageBox.Show("Value = " + nudKeyDuration.Value.ToString());
            //MessageBox.Show(float.Parse(nudKeyDuration.Value.ToString()).ToString());

            CommandVO newCommand = new CommandVO();

            newCommand.method    = "clipboard";
            newCommand.speech    = tbSpeech.Text;
            newCommand.clipboard = rtClipboard.Text;
            //newCommand.duration = float.Parse(nudKeyDuration.Value.ToString());
            newCommand.duration           = 0;
            newCommand.clipboardAutoPaste = cbAutoPaste.Checked;

            ui.grammarHandler.addCommand(newCommand);


            exitToMain = true;
            this.Close();

            ui.profileHandler.save();
        }
コード例 #6
0
        public void loadCommands(XmlNodeList arg, String profileName)
        {
            ui.log("GrammarHandler.loadCommands(xmlNodeList)");
            xmlCommands = arg;

            if (xmlCommands.Count == 0)
            {
                //MessageBox.Show("Please add some commands")
                lvCommands.Clear();
                ui.setStatus("Profile is empty, please createa some commands!");
                return;
            }

            if (commands != null)
            {
                commands.Clear();
            }



            // Reset
            //ui.recognizer.sre.Dispose();
            clear();


            // Configure ListView
            lvCommands.Clear();
            lvCommands.View      = View.Details;
            lvCommands.GridLines = true;
            lvCommands.Sorting   = SortOrder.Ascending;
            lvCommands.Columns.Add("Command", 500, HorizontalAlignment.Left);
            lvCommands.Columns.Add("Type", 146, HorizontalAlignment.Left);


            int cnt = 0;


            //Console.WriteLine("##### " + xmlCommands.Count);

            ui.log("---------------");
            foreach (XmlNode node in xmlCommands)
            {
                String speech = node.ChildNodes[0].InnerText.ToString();
                if (speech != "")
                {
                    cnt++;
                    speechCommands.Add(node.ChildNodes[0].InnerText.ToString());

                    //Console.WriteLine(command.InnerXml.ToString());
                    //Console.WriteLine(node.ChildNodes[0].InnerText);
                    //ui.log(node.ChildNodes[0].InnerText.ToString());

                    CommandVO command = new CommandVO();

                    command.method          = node.Attributes[0].InnerText.ToString();
                    command.haltOnAppChange = intStringToBoolean(node.Attributes[1].InnerText.ToString());
                    command.duration        = float.Parse(node.Attributes[2].InnerText.ToString());

                    command.speech    = node.ChildNodes[0].InnerText;
                    command.window    = node.ChildNodes[1].InnerText;
                    command.autoType  = node.ChildNodes[2].InnerText;
                    command.clipboard = node.ChildNodes[3].InnerText;
                    //Console.WriteLine("node.ChildNodes[3].Attributes[0].ToString() = " + node.ChildNodes[3].Attributes[0].Value.ToString());
                    command.clipboardAutoPaste = intStringToBoolean(node.ChildNodes[3].Attributes[0].Value.ToString());
                    command.multiKey           = node.ChildNodes[4].InnerText;
                    command.multiKeyCtrl       = intStringToBoolean(node.ChildNodes[4].Attributes[0].Value.ToString());
                    command.multiKeyAlt        = intStringToBoolean(node.ChildNodes[4].Attributes[1].Value.ToString());
                    command.multiKeyShift      = intStringToBoolean(node.ChildNodes[4].Attributes[2].Value.ToString());

                    ListViewItem listViewItem = new ListViewItem(command.speech);
                    listViewItem.SubItems.Add(command.method);
                    lvCommands.Items.Add(listViewItem);

                    commands.Add(command);

                    //ui.log(command.speech + ": " + "\t" + "method:" + command.method.ToString() + "\t" + "haltOnAppChange:" + command.haltOnAppChange.ToString() + "\t" + "+delay:" + command.delay.ToString());
                    ui.log("Command added: [" + command.speech + "]");
                    //ui.log("command.clipboard: [\n" + command.clipboard + "\n]");

                    //Server.UrlDecode
                }
            }
            ui.log("---------------");


            ui.stopListening();

            gb = new GrammarBuilder(speechCommands);
            g  = new Grammar(gb);
            ui.recognizer.sre.LoadGrammar(g);
            ui.recognizer.sre.RecognizeAsync(RecognizeMode.Multiple);


            ui.setStatus(cnt.ToString() + " commands loaded and ready!");


            EventHandler handler = grammarLoaded;

            if (null != handler)
            {
                handler(this, EventArgs.Empty);
            }
        }
コード例 #7
0
 public void addCommand(CommandVO cvo)
 {
     commands.Add(cvo);
 }