public void Register(HotkeyData hotkey) { if (hotkey.IsEmpty) { return; } Entry entry; if (_data.ContainsKey(hotkey)) { entry = _data[hotkey]; } else { entry = _data[hotkey] = new Entry { Id = ++_lastId, Hotkey = hotkey }; User32.RegisterHotKey(_window.Handle, entry.Id, hotkey.GetInteropModifiers(), (uint)hotkey.Key); } entry.RefCount++; Trace.WriteLine($"HotkeyManager: Register: {hotkey}"); }
private void WndProc(Message msg) { if (msg.Msg == User32.WM_HOTKEY) { var hotkey = new HotkeyData(msg); Trace.WriteLine($"HotkeyManager: KeyPressed: {hotkey}"); KeyPressed?.Invoke(hotkey); } }
public void Unregister(HotkeyData hotkey) { var entry = _data[hotkey]; entry.RefCount--; Trace.WriteLine($"HotkeyManager: Unregister: {hotkey} {entry.RefCount}"); if (entry.RefCount == 0) { User32.UnregisterHotKey(_window.Handle, entry.Id); _data.Remove(hotkey); } }