Exemple #1
0
        /// <summary>
        /// Create a string from a WinHotkey
        /// </summary>
        /// <param name="key">The WinHotkey</param>
        /// <returns>A string of keynames</returns>
        public static string ToString(WinHotkey key)
        {
            // MUST match the FromString above
            string ret = "";

            foreach (var k in key)
            {
                ret += $"{k} ";
            }
            return(ret.TrimEnd( ));
        }
Exemple #2
0
        /// <summary>
        /// Add a Hotkey to the list (no checks for potentially problematic cases here..)
        ///  NOTE: The Action may only last some milliseconds, else the KeyHook will be unhooked by Windows (see doc)
        /// </summary>
        /// <param name="hotkey"></param>
        /// <param name="tag">A unique ID</param>
        /// <param name="onKey">An Action(string) which is exec when the Hotkey is pressed</param>
        public void AddKey(WinHotkey hotkey, string tag, Action <string> onKey)
        {
            if (!hotkey.isValid)
            {
                return;              // sanity
            }
            // translate from WinHotkey
            KeyModifier modifierPattern = KeyModifier.None;

            foreach (var mod in hotkey.Modifier)
            {
                modifierPattern |= GetModFromWinKey(mod);
            }
            AddKey(hotkey.Key, modifierPattern, tag, onKey);
        }
Exemple #3
0
        // String serialization

        /// <summary>
        /// Create a Hotkey from a string of keynames (space separated)
        ///  - from WinHotkey.AsString
        /// </summary>
        /// <param name="hkString">The hotkey string</param>
        /// <returns>A WinHotkey</returns>
        public static WinHotkey FromString(string hkString)
        {
            // MUST match the ToString below
            var ret = new WinHotkey();

            string[] e = hkString.Split(new char[] { ' ' });
            foreach (var s in e)
            {
                if (Enum.TryParse(s, out Keys key))
                {
                    ret.Add(key);
                }
            }
            return(ret);
        }
Exemple #4
0
 /// <summary>
 /// cTor: Copy Constructor
 /// </summary>
 /// <param name="hotkey">A WinHotkey</param>
 public WinHotkey(WinHotkey hotkey)
 {
     this.AddRange(hotkey);
 }