Beispiel #1
0
        private void RegisterHotKey()
        {
            //HotKeyHelper.RegisterHotKey(this.Handle, HotKeyHelper.HOTKEY_ID, HotKeyHelper.KeyModifiers.Control | HotKeyHelper.KeyModifiers.Shift, Keys.N);
            //HotKeyHelper.RegisterHotKey(this.Handle, HotKeyHelper.HOTKEY_ID, HotKeyHelper.KeyModifiers.None, Keys.F4);

            var startKeys      = KeysHelper.ClearModifiers(keysTextBox시작_키.SelectedKeys);
            var startModifiers = KeysHelper.CovertToHotKeyModifiers(keysTextBox시작_키.SelectedKeys);

            var endKeys      = KeysHelper.ClearModifiers(keysTextBox종료_키.SelectedKeys);
            var endModifiers = KeysHelper.CovertToHotKeyModifiers(keysTextBox종료_키.SelectedKeys);

            if (startKeys == endKeys &&
                startModifiers == endModifiers)
            {
                if (startKeys != Keys.None)
                {
                    HotKeyHelper.RegisterHotKey(this.Handle, HotKeyHelper.HOTKEY_ID_START_MACRO, startModifiers, startKeys);
                }
            }
            else
            {
                if (startKeys != Keys.None)
                {
                    HotKeyHelper.RegisterHotKey(this.Handle, HotKeyHelper.HOTKEY_ID_START_MACRO, startModifiers, startKeys);
                }

                if (endKeys != Keys.None)
                {
                    HotKeyHelper.RegisterHotKey(this.Handle, HotKeyHelper.HOTKEY_ID_END_MACRO, endModifiers, endKeys);
                }
            }
        }
Beispiel #2
0
        protected override void WndProc(ref Message message)
        {
            switch (message.Msg)
            {
            case HotKeyHelper.WM_HOTKEY:
            {
                Keys key = (Keys)(((int)message.LParam >> 16) & 0xFFFF);
                HotKeyHelper.KeyModifiers modifier = (HotKeyHelper.KeyModifiers)((int)message.LParam & 0xFFFF);

                if (keysTextBox시작_키.Focused)
                {
                    keysTextBox시작_키.SelectedKeys = key | KeysHelper.CovertToHotKeyModifiersForHelpers(modifier);
                    break;
                }

                if (keysTextBox종료_키.Focused)
                {
                    keysTextBox종료_키.SelectedKeys = key | KeysHelper.CovertToHotKeyModifiersForHelpers(modifier);
                    break;
                }

                var startKeys      = KeysHelper.ClearModifiers(keysTextBox시작_키.SelectedKeys);
                var startModifiers = KeysHelper.CovertToHotKeyModifiers(keysTextBox시작_키.SelectedKeys);

                var endKeys      = KeysHelper.ClearModifiers(keysTextBox종료_키.SelectedKeys);
                var endModifiers = KeysHelper.CovertToHotKeyModifiers(keysTextBox종료_키.SelectedKeys);

                //if ((HotKeyHelper.KeyModifiers.Control | HotKeyHelper.KeyModifiers.Shift) == modifier && Keys.N == key)
                //if ((HotKeyHelper.KeyModifiers.None) == modifier && Keys.F4 == key)
                if (startModifiers == modifier &&
                    startKeys == key)
                {
                    // 시작 키, 종료 키가 같을 경우에는 토글
                    if (startKeys == endKeys &&
                        startModifiers == endModifiers)
                    {
                        ToggleMacro();
                    }
                    else
                    {
                        StartMacro();
                    }
                }
                else if (endModifiers == modifier &&
                         endKeys == key)
                {
                    EndMacro();
                }
            }
            break;
            }
            base.WndProc(ref message);
        }
        public void ClearModifiers()
        {
            // 준비

            // 작업
            var result  = KeysHelper.ClearModifiers(Keys.A);
            var result1 = KeysHelper.ClearModifiers(Keys.A | Keys.Control);
            var result2 = KeysHelper.ClearModifiers(Keys.A | Keys.Alt | Keys.Control);
            var result3 = KeysHelper.ClearModifiers(Keys.A | Keys.Shift);

            // 확인
            Assert.IsTrue(result != null);
        }