public void RegisterHotKey(string name, string combineKeys, EventHandler <HotkeyEventArgs> handler) { var rawHotKey = RawHotKey.Parse(combineKeys); if (rawHotKey.Key != Key.None || rawHotKey.HotKeyModifiers != ModifierKeys.None) { RegisterHotKey(name, rawHotKey.HotKeyModifiers, KeyInterop.VirtualKeyFromKey(rawHotKey.Key), handler); } }
public static RawHotKey Parse(string hotKeyStr) { List <ModifierKeys> hotKeyModifiers = new List <ModifierKeys>(); Key key = Key.None; hotKeyStr = hotKeyStr.Trim(); if (hotKeyStr.Length == 0) { return(new RawHotKey(hotKeyModifiers, key)); } var keys = hotKeyStr.Split("+"); if (keys.Length == 0) { return(new RawHotKey(hotKeyModifiers, key)); } foreach (string k in keys) { ModifierKeys hkm; if (ParseHotKeyModifiers(k, out hkm)) { hotKeyModifiers.Add(hkm); } else if (key != Key.None) { throw new InvalidHotKeyStringException("Invalid hotkey string: " + hotKeyStr + ". Mutilple key found."); } else { if (!Enum.TryParse(k, out key)) { throw new InvalidHotKeyStringException("Invalid hotkey string: " + hotKeyStr + ". Invalid key."); } } } var rawHotKey = new RawHotKey(hotKeyModifiers, key); return(rawHotKey); }