Exemple #1
0
        public bool Register(ModifierKeys modkey, Key key, EventHandler handler)
        {
            var modKeyNum = (int)modkey;
            var vKey      = KeyInterop.VirtualKeyFromKey(key);

            while (this._hotkeyID < MAX_HOTKEY_ID)
            {
                var ret = RegisterHotKey(this._windowHandle, this._hotkeyID, modKeyNum, vKey);

                if (ret != 0)
                {
                    var hotkey = new HotKeyItem(modkey, key, handler);
                    this._hotkeyList.Add(this._hotkeyID, hotkey);
                    this._hotkeyID++;
                    return(true);
                }
                else
                {
                    MessageBox.Show($"登録に失敗\n{modkey} + {key} は、他のアプリで登録済み");
                    return(false);
                }
                //this._hotkeyID++;
            }

            return(false);
        }
Exemple #2
0
        private void ComponentDispatcher_ThreadPreprocessMessage(ref MSG msg, ref bool handled)
        {
            if (msg.message != WM_HOTKEY)
            {
                return;
            }
            int        id     = msg.wParam.ToInt32();
            HotKeyItem hotkey = this._hotkeyList[id];

            hotkey?.Handler
            ?.Invoke(this, EventArgs.Empty);
        }