public static TParentHotkeyInvoker Create(int id, TKeyEventArgs keyEventArgs, Action <TChildHotkey> unregister) { var hotkeyInvoker = new TParentHotkeyInvoker(id, keyEventArgs, out Action <EHotkeyState> invokeHotkey, unregister); hotkeyInvoker.Invoke = invokeHotkey; return(hotkeyInvoker); }
public TParentHotkey(int id, TKeyEventArgs keyEventArgs, out Action <EHotkeyState> invokeHotkeyFired, Action <TChildHotkey> unregister) { Id = id; KeyEventArgs = keyEventArgs; invokeHotkeyFired = this.invokeHotkeyFired; this.unregister = unregister; hotkeys = new List <TChildHotkeyInvoker>(); }
/// <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()); } }
private TParentHotkeyInvoker(int id, TKeyEventArgs keyEventArgs, out Action <EHotkeyState> invokeHotkeyFired, Action <TChildHotkey> unregister) : base(id, keyEventArgs, out invokeHotkeyFired, unregister) { }