Пример #1
0
 /// <summary>
 /// Adds a key map to the key map dictionary.
 /// </summary>
 /// <param name="keyMap">The new key map.</param>
 /// <returns>Returns true if the key map was successfully added, otherwise false
 /// (means there is already a key map with the same description).</returns>
 public static bool AddKeyMap(KeyMap keyMap)
 {
     if (keyMaps.ContainsKey(keyMap.Description))
     {
         return(false);
     }
     else
     {
         keyMaps.Add(keyMap.Description, keyMap);
         return(true);
     }
 }
Пример #2
0
        /// <summary>
        /// Initializes the keyMap dictionary with the default key map
        /// and loads all key map files from the key maps directory.
        /// </summary>
        internal static void LoadKeyMaps(string keyMapsDirectory)
        {
            keyMaps = new Dictionary <string, KeyMap>();

            try
            {
                if (Directory.Exists(keyMapsDirectory))
                {
                    string[] files = Directory.GetFiles(keyMapsDirectory, "*.xml");
                    foreach (string file in files)
                    {
                        XmlDocument xmlFile = new XmlDocument();
                        xmlFile.Load(file);

                        XmlNode keymapNode = xmlFile.GetElementsByTagName("keymap")[0];
                        if (keymapNode != null)
                        {
                            KeyMap keyMap = new KeyMap(keymapNode.Attributes["description"].Value);
                            if (!keyMaps.ContainsKey(keyMap.Description))
                            {
                                foreach (XmlNode node in keymapNode.SelectNodes("key"))
                                {
                                    XmlAttribute modifierNode = node.Attributes["modifier"];

                                    Keys        key      = (Keys)Enum.Parse(typeof(Keys), node.Attributes["keys"].Value, true);
                                    KeyModifier modifier = modifierNode == null ? KeyModifier.None :
                                                           (KeyModifier)Enum.Parse(typeof(KeyModifier), modifierNode.Value, true);
                                    char ch = node.InnerText.Length == 1 ? node.InnerText.ToCharArray(0, 1)[0] : ' ';

                                    keyMap.AddChar(key, modifier, ch);
                                }
                                keyMaps.Add(keyMap.Description, keyMap);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error loading key maps: " + ex.Message);
            }
        }