예제 #1
0
 public Int32 RemoveAction(KeyboardAction action)
 {
     if (this.Actions.Remove(action))
     return 1;
     else
     return 0;
 }
예제 #2
0
        /// <summary>
        /// Adds a hotkey assignment to the kbd file.
        /// </summary>
        /// <param name="macroName">The name of the macroscript to be called.</param>
        /// <param name="macroCategory">The category of the macroscript to be called.</param>
        /// <param name="keys">The keys associated with the hotkey assignment.</param>
        /// <param name="replace">Whether to replace an assignment with the same keys if it already exists.</param>
        /// <returns>True if the hotkey assignment was added, false if the exact assignment already existed or if it should not be replaced.</returns>
        public Boolean AddAction(String macroName, String macroCategory, Keys keys, Boolean replace)
        {
            KeyboardAction existingAction = this.Actions.Find(a => (a.TableId == MainTableId || a.TableId == MacroTableId) && a.Keys == keys);
            if (existingAction != null)
            {
            if (!replace || (existingAction.MacroName == macroName && existingAction.MacroCategory == macroCategory))
                return false;
            else
                this.Actions.Remove(existingAction);
            }

            KeyboardAction action = new KeyboardAction { MacroName = macroName, MacroCategory = macroCategory, Keys = keys, TableId = MacroTableId };
            Int32 insertLocation = this.Actions.FindLastIndex(a => a.TableId == MacroTableId) + 1;
            if (insertLocation == 0)
            insertLocation = this.Actions.Count;

            this.Actions.Insert(insertLocation, action);

            return true;
        }
예제 #3
0
        /// <summary>
        /// Reads and parses a KBD file from a stream.
        /// </summary>
        /// <returns>True when successful.</returns>
        public Boolean Read(Stream stream)
        {
            using (StreamReader reader = new StreamReader(stream))
            {
            this.Actions.Clear();

            while(!reader.EndOfStream)
            {
                try
                {
                    //KBD Line format:
                    //18=7 38 51 1127307088
                    //index=modkeycode keycode persistent_id table_id
                    //9=3 82 SmartScale`Tools 647394
                    //index=modkeycode keycode macroname`macrocategory table_id

                    String line = reader.ReadLine();
                    List<String> line_split = new List<string>();
                    String[] split = line.Split('=');
                    line_split.Add(split[0]);
                    line_split.AddRange(split[1].Split(' '));

                    if (line_split.Count < 5)
                        continue;

                    KeyboardAction action = new KeyboardAction();
                    action.Keys = modKeycodeToKeys(Int32.Parse(line_split[1])) | (Keys)Enum.Parse(typeof(Keys), line_split[2]);
                    action.TableId = UInt32.Parse(line_split[line_split.Count - 1]);

                    if (line_split.Count > 5 || !UInt32.TryParse(line_split[3], out action.PersistentId))
                    {
                        String macro = line_split[3];
                        for (int i = 4; i < (line_split.Count - 1); i++)
                            macro += " " + line_split[i];

                        if (System.Text.RegularExpressions.Regex.IsMatch(macro, @"\S`\S"))
                        {
                            String[] macro_split = macro.Split('`');
                            action.MacroName = macro_split[0];
                            action.MacroCategory = macro_split[1];
                        }
                        else
                        {
                            action.MacroName = macro;
                            action.MacroCategory = String.Empty;
                        }
                    }

                    this.Actions.Add(action);

                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            }

            return true;
        }