// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void processCommand(String command) { t.log("CommandExecutionHandler.processCommand(" + command + ")"); cvo = fm.commandManager.getCommand(command); if (cvo != null) { t.log("CommandExecutionHandler.processCommand(" + command + "): Command found!"); /* * IntPtr handle = GetActiveWindow(); * SendKeys.Send("*****@*****.**"); */ t.log("CommandExecutionHandler.processCommand(): cvo.commandItems.Count = " + cvo.commandItems.Count); if (cvo.commandItems.Count > 0) { startTimedCommandItemExecution(); } } else { t.log("CommandExecutionHandler.processCommand(" + command + "): Command not found!"); } }
public CommandVO clone() { CommandVO copy = new CommandVO(); copy.speech = this.speech; copy.delayBetweenCommands = this.delayBetweenCommands; foreach (CommandItemVO item in commandItems) { CommandItemVO itemCopy = new CommandItemVO(); itemCopy.altPressed = item.altPressed; itemCopy.applicationParams = item.applicationParams; itemCopy.applicationPath = item.applicationPath; itemCopy.appVarIndex = item.appVarIndex; itemCopy.appVars = item.appVars; itemCopy.clipboard = item.clipboard; itemCopy.clipboardAutoPaste = item.clipboardAutoPaste; itemCopy.ctrlPressed = item.ctrlPressed; itemCopy.delayBeforeFocus = item.delayBeforeFocus; itemCopy.delayTime = item.delayTime; itemCopy.key = item.key; itemCopy.shiftPressed = item.shiftPressed; itemCopy.stopIfFocusNotFound = item.stopIfFocusNotFound; itemCopy.type = item.type; itemCopy.varToClipboardAutoPaste = item.varToClipboardAutoPaste; copy.commandItems.Add(itemCopy); } return(copy); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void addCommand(CommandVO cvo) { t.log("CommandManager.addCommand(cvo)"); commands.Add(cvo); fm.fmCommandListController.updateCommandListView(); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void deleteCommand() { t.log("CommandManager.deleteCommand()"); String selectedItemSpeechCommand = fm.fmCommandListController.getSelectedItemSpeechCommand(); CommandVO cvoToRemove = this.getCommand(selectedItemSpeechCommand); commands.Remove(cvoToRemove); cvoToRemove = null; fm.fmCommandListController.updateCommandListView(); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public CommandVO getCommand(String speech) { CommandVO cvo = null; foreach (CommandVO c in commands) { if (c.speech == speech) { cvo = c; } } return(cvo); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public FormCommandEditor(CommandVO cvoToEdit = null) { InitializeComponent(); // Class specific debug t = new T(true); t.log("FormCommandEditor(cvoToEdit=null)"); fm = Vars.formMain; this.cvoToEdit = cvoToEdit; // Populate winforms as we have a CVO to edit if (cvoToEdit != null) { this.tbSpeech.Text = cvoToEdit.speech; this.tbCommandDelay.Text = cvoToEdit.delayBetweenCommands.ToString(); } // Populate lvCommands lvCommands.Clear(); lvCommands.Items.Clear(); lvCommands.View = View.Details; //lvCommands.Height = 70; lvCommands.GridLines = true; lvCommands.Sorting = SortOrder.Ascending; lvCommands.HeaderStyle = ColumnHeaderStyle.None; lvCommands.Columns.Add("Command name", lvCommands.Width); //lvProfiles.Columns.Add("Type", 146, HorizontalAlignment.Left); lvCommands.Columns[0].AutoResize(ColumnHeaderAutoResizeStyle.None); lvCommands.Items.Add("1. Insert text into clipboard"); lvCommands.Items.Add("2. Combination key"); lvCommands.Items.Add("3. Open application"); // TO DO /* * lvCommands.Items.Add("4. Get application focus"); * lvCommands.Items.Add("5. Delay"); * lvCommands.Items.Add("6. Clipboard to variable"); * lvCommands.Items.Add("7. Variable to clipboard"); */ }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public FormCommandEditorCommandManager(FormCommandEditor formCommandEditor) { // Class specific debug t = new T(true); t.log("FormCommandEditorCommandManager()"); fce = formCommandEditor; if (fce.cvoToEdit == null) { cvo = new CommandVO(); } else { cvo = fce.cvoToEdit; } }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - private void btnEditCommand_Click(object sender, EventArgs e) { t.log("\n\n\nFormMain.btnEditCommand_Click()"); if (lvCommands.SelectedItems.Count < 1) { MessageBox.Show("Please select a command to edit first!"); return; } speechRecognizer.stopListening(); this.Hide(); CommandVO selectedCommandVO = commandManager.getCommand(lvCommands.SelectedItems[0].Text); CommandVO cvoToEdit = selectedCommandVO.clone(); //int selectedCommandVOIndex = lvCommands.SelectedIndices[0]; formCommandEditor = new FormCommandEditor(cvoToEdit); formCommandEditor.Show(); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - private void btnSave_Click(object sender, EventArgs e) { t.log("FormCommandEditor.btnSave_Click()"); if (tbSpeech.Text.Length == 0) { MessageBox.Show("Please enter a speech command before saving!"); return; } // Check if we are updating the same command or not if (cvoToEdit != null) { if (cvoToEdit.speech == tbSpeech.Text) { // Same command, no check required } else { // command has been renamed, check for duplicates if (checkIfCommandExists()) { MessageBox.Show("A command already exists using that speech, please enter a different speech command."); return; } } } else { // Command is new, check for duplicates if (checkIfCommandExists()) { MessageBox.Show("A command already exists using that speech, please enter a different speech command."); return; } } CommandVO newCommandVO = fceCommandManager.cvo; t.log("FormCommandEditor.btnSave_Click(): newCommandVO.commandItems.Count = " + newCommandVO.commandItems.Count); newCommandVO.speech = tbSpeech.Text; newCommandVO.delayBetweenCommands = float.Parse(tbCommandDelay.Text); if (cvoToEdit == null) { // New command mode fm.commandManager.addCommand(newCommandVO); } else { // Edit command mode (delete selected in update and then add new) fm.commandManager.updateCommand(newCommandVO); } fm.grammarHandler.loadCommands(); fm.Show(); this.Close(); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - public void getCommandsFromLoadedProfile() { t.log("CommandManager.getCommandsFromLoadedProfile()"); fm.setStatus("Parsing profile commands..."); commands = new List <CommandVO>(); XmlNodeList xmlCommandsList = fm.profileManager.xmlDoc.SelectNodes("//command"); //t.log("\t" + "xmlCommandsList.Count = " + xmlCommandsList.Count); //t.log("\t" + "xmlCommandsList.GetType = " + xmlCommandsList.GetType()); t.log("------------------------------------------------------------"); foreach (XmlNode commandRootNode in xmlCommandsList) { //t.log("\t" + commandRootNode.ChildNodes[0].InnerText.ToString()); // Parse the outer VO (ID = String speech) CommandVO cvo = new CommandVO(); cvo.speech = commandRootNode.ChildNodes[0].InnerText.ToString(); // Parse the inner VO (list) XmlNodeList xmlCommandItems = commandRootNode.SelectNodes("command_sequence/item"); //t.log("\t\t" + "CommandItem: " + xmlCommandItems.ToString()); t.log("\n"); t.log("\t\t" + "command = " + cvo.speech); //Console.WriteLine("###### " + commandRootNode.ChildNodes[1].OuterXml.ToString()); foreach (XmlNode commandItemNode in xmlCommandItems) { //t.log("\t\t" + "CommandItem: " + commandItemNode.OuterXml.ToString()); //t.log("\t\t\t" + "XML = " + commandItemNode.OuterXml.ToString()); String commandItemType = commandItemNode.Attributes[0].Value.ToString(); CommandItemVO civo = new CommandItemVO(); civo.type = commandItemType; int index = -1; t.log("\t\t" + "commandItemType = " + commandItemType); switch (commandItemType) { case "run application": t.log("\t\t\t" + commandItemNode.ChildNodes[0].InnerXml.ToString()); civo.applicationPath = commandItemNode.ChildNodes[0].InnerXml.ToString(); t.log("\t\t\t" + commandItemNode.ChildNodes[1].InnerXml.ToString()); civo.applicationParams = commandItemNode.ChildNodes[1].InnerXml.ToString(); break; case "clipboard": t.log("\t\t\t" + "commandItemNode.InnerText = " + commandItemNode.InnerText.ToString()); t.log("\t\t\t" + "commandItemNode.Attributes[1].Value = " + commandItemNode.Attributes[1].Value.ToString()); civo.clipboard = commandItemNode.InnerText.ToString(); civo.clipboardAutoPaste = DTools.intStringToBoolean(commandItemNode.Attributes[1].Value.ToString()); break; case "clipboard to var": index = int.Parse(commandItemNode.Attributes[1].Value.ToString()); civo.appVarIndex = index; civo.appVars[index] = Clipboard.GetText(); //t.log("\t\t\t" + "index = " + index.ToString()); //t.log("\t\t\t" + "civo.appVars[index] = " + civo.appVars[index].ToString()); break; case "var to clipboard": //index = int.Parse(commandItemNode.Attributes[1].Value.ToString()); //Clipboard.SetText(civo.appVars[index]); break; case "output var": //index = int.Parse(commandItemNode.Attributes[1].Value.ToString()); break; case "key": civo.key = commandItemNode.ChildNodes[0].InnerText.ToString(); civo.ctrlPressed = DTools.intStringToBoolean(commandItemNode.Attributes[1].Value.ToString()); civo.altPressed = DTools.intStringToBoolean(commandItemNode.Attributes[2].Value.ToString()); civo.shiftPressed = DTools.intStringToBoolean(commandItemNode.Attributes[3].Value.ToString()); break; case "focus on application": break; case "delay": t.log("\t\t\t" + "commandItemNode.Attributes[1].Value = " + commandItemNode.Attributes[1].Value.ToString()); civo.delayTime = float.Parse(commandItemNode.Attributes[1].Value); break; } cvo.addCommandItem(civo); } // commandItemNode for loop end //t.log("\t----------------------------------"); commands.Add(cvo); } // rootCommandNode for loop end t.log("------------------------------------------------------------"); //Console.WriteLine(commands.ToString()); fm.setStatus("Profile commands parsed..."); fm.fmCommandListController.updateCommandListView(); }