예제 #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);
            }
        }