Example #1
0
        /// <summary>
        /// Map a key to an action code.
        /// </summary>
        /// <param name="keyData">Key data to map</param>
        /// <returns>An ActionID or ActionID.None</returns>
        public static ActionID MapKeyToAction(Keys keyData)
        {
            KeysConverter kc           = new KeysConverter();
            string        convertedKey = kc.ConvertToString(keyData);

            ActionID result = ActionID.None;

            if (convertedKey != null)
            {
                // Try any custom key fields before the stock fields
                UIConfigKeysKey ky = null;
                if (Keys.customkey != null)
                {
                    ky = Keys.customkey.FirstOrDefault(key => String.Equals(key.code, convertedKey, StringComparison.CurrentCultureIgnoreCase));
                }
                if (ky == null)
                {
                    ky = Keys.key.FirstOrDefault(key => String.Equals(key.code, convertedKey, StringComparison.CurrentCultureIgnoreCase));
                }
                if (ky != null)
                {
                    Enum.TryParse(ky.name, true, out result);
                }
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// Return a string that represents the key used for the specified action.
        /// </summary>
        /// <param name="actionId">The action ID</param>
        /// <returns>The key string</returns>
        public static string MapActionToKeyString(ActionID actionId)
        {
            string actionEnum = actionId.ToString();

            UIConfigKeysKey ky = null;

            if (Keys.customkey != null)
            {
                ky = Keys.customkey.FirstOrDefault(key => String.Equals(key.name, actionEnum, StringComparison.CurrentCultureIgnoreCase));
            }
            if (ky == null)
            {
                ky = Keys.key.FirstOrDefault(key => String.Equals(key.name, actionEnum, StringComparison.CurrentCultureIgnoreCase));
            }
            if (ky != null)
            {
                switch (ky.code)
                {
                case "Oemcomma":    return(",");

                case "OemPeriod":   return(".");

                case "Left":        return("←");

                case "Right":       return("→");
                }
                return(ky.code);
            }
            return(string.Empty);
        }