Пример #1
0
        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}");
        }
Пример #2
0
 private void WndProc(Message msg)
 {
     if (msg.Msg == User32.WM_HOTKEY)
     {
         var hotkey = new HotkeyData(msg);
         Trace.WriteLine($"HotkeyManager: KeyPressed: {hotkey}");
         KeyPressed?.Invoke(hotkey);
     }
 }
Пример #3
0
        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);
            }
        }