/// <summary> /// Registers a hotkey. To register only a modifier: set it as <see cref="TKeyEventArgs.KeyCode"/>. /// </summary> /// <param name="args"></param> /// <returns>Hotkey id. You have to unregister it.</returns> public TChildHotkey RegisterHotkey(TKeyEventArgs args) { TParentHotkeyInvoker hotkeyInvoker = null; if (!registeredHotkeys.Any((x) => { if (x.Value.KeyEventArgs.Modifiers == args.Modifiers && x.Value.KeyEventArgs.KeyCode == args.KeyCode) { hotkeyInvoker = x.Value; return(true); } // return(false); })) { if (registeredHotkeys.Count == 0) { start(); } int id = 0; do { id++; } while (registeredHotkeys.Any(x => x.Value.Id == id)); hotkeyInvoker = TParentHotkeyInvoker.Create(id, args, (childHotkey) => UnregisterHotkey(id)); registeredHotkeys.Add(id, hotkeyInvoker); return(hotkeyInvoker.RegisterChildren()); } else { hotkeyInvoker.Counter++; return(hotkeyInvoker.RegisterChildren()); } }