예제 #1
0
 protected void InvokeKeyUp(BaseKeyboardManager sender, HotkeyEventArgs args)
 {
     if (KeyUp != null)
     {
         KeyUp(sender, args);
     }
 }
예제 #2
0
        protected HotkeyEventArgs InvokeKeyUp(BaseKeyboardManager sender, Hotkey args)
        {
            HotkeyEventArgs ar = null;

            if (KeyUp != null)
            {
                KeyUp(sender, ar = HotkeyEventArgs.Create(args));
            }
            return(ar);
        }
예제 #3
0
        public static HotkeyEventArgs Create(Hotkey hk)
        {
            if (hk == null)
            {
                return(null);
            }
            var args = new HotkeyEventArgs {
                Hotkey = hk
            };

            return(args);
        }
예제 #4
0
        private void process_keyevent(KeyEventProcessArgs e)
        {
            int wParam = e.wParam;
            var lParam = e.lParam;

            var keyc     = ((KeyCode)lParam.vkCode);
            var key      = keyc.ToKeys();
            var modifier = ModKeys.None;

            if ((!SuppressKeyHold || duplicatetags[(int)keyc] != (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)))
            {
                #region Modifier Switches
                if (keyc.IsModifier())
                {
                    switch (keyc)
                    {
                    case KeyCode.RControl:
                        rctrl = wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN;     //is key down? otherwise false.
                        break;

                    case KeyCode.LControl:
                        lctrl = wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN;     //is key down? otherwise false.
                        break;

                    case KeyCode.RAlt:
                        ralt = wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN;     //is key down? otherwise false.
                        break;

                    case KeyCode.LAlt:
                        lalt = wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN;     //is key down? otherwise false.
                        break;

                    case KeyCode.RShift:
                        rshift = wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN;     //is key down? otherwise false.
                        break;

                    case KeyCode.LShift:
                        lshift = wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN;     //is key down? otherwise false.
                        break;
                    }
                }
                else
                {
                    if (rctrl)
                    {
                        modifier |= ModKeys.RControl;
                    }
                    if (lctrl)
                    {
                        modifier |= ModKeys.LControl;
                    }
                    if (rshift)
                    {
                        modifier |= ModKeys.RControl;
                    }
                    if (lshift)
                    {
                        modifier |= ModKeys.LShift;
                    }
                    if (ralt)
                    {
                        modifier |= ModKeys.RAlt;
                    }
                    if (lalt)
                    {
                        modifier |= ModKeys.LAlt;
                    }
                }


                #endregion
                #region Args and Event firing

                //Console.WriteLine("(" + ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) ? "D" : "U") + ") " + modifier.ToString() + " + " + key.ToString());

                Hotkey          hotk;
                HotkeyEventArgs args = null;
                if ((hotk = base._registers.FirstOrDefault(hk => hk.Key.Equals(key) && hk.Modifiers.Compare(modifier))) != null)
                {
                    //keydown
                    if ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN))
                    {
                        args = InvokeKeyDown(this, hotk);
                    }
                    else     //key up
                    {
                        if ((wParam == WM_KEYUP || wParam == WM_SYSKEYUP))
                        {
                            args = InvokeKeyUp(this, hotk);

                            //if equals to last key event is up and equals to this key event -> KeyPress
                            // hotkey mode: /*tmp_key.CompareModifiers(key) && tmp_mods.CompareModifiers(modifier) && !(wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)*/
                            if (args == null || (args.Handled == false && presstags[(int)keyc]))
                            {
                                args = InvokeKeyPress(this, hotk);
                            }
                        }
                    }
                }

                /*if (args != null && args.Handled)
                 *      return 1;*/

                #endregion


                presstags[(int)keyc] = wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN;
#if DEBUG_KEYS
                Console.Clear();
                Console.WriteLine("RCTRL " + rctrl + " | " + "LCTRL " + lctrl + " | " + "RAlt " + ralt + " | " + "LAlt " + lalt + " | ");
                Console.WriteLine("RShift " + rshift + " | " + "LShift " + lshift);
                Console.WriteLine(Hotkey.Create(key, modifier, "").ToString());
#endif
            }
            if ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) && duplicatetags[(int)keyc] == false)
            {
                duplicatetags[(int)keyc] = true;
            }
            else if ((wParam == WM_KEYUP || wParam == WM_SYSKEYUP) && duplicatetags[(int)keyc] == true)
            {
                duplicatetags[(int)keyc] = false;
            }
        }
예제 #5
0
파일: KeyboardLogger.cs 프로젝트: Nucs/nlib
        private void process_keyevent(KeyEventProcessArgs e)
        {
            int wParam = e.wParam;
            var lParam = e.lParam;

            var keyc     = ((KeyCode)lParam.vkCode);
            var key      = keyc.ToKeys();
            var modifier = ModKeys.None;

            if ((!SuppressKeyHold || duplicatetags[(int)keyc] != (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)))
            {
                #region Modifier Switches
                if (keyc.IsModifier())
                {
                    switch (keyc)
                    {
                    case KeyCode.RControl:
                        rctrl = wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN;     //is key down? otherwise false.
                        break;

                    case KeyCode.LControl:
                        lctrl = wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN;     //is key down? otherwise false.
                        break;

                    case KeyCode.RAlt:
                        ralt = wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN;     //is key down? otherwise false.
                        break;

                    case KeyCode.LAlt:
                        lalt = wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN;     //is key down? otherwise false.
                        break;

                    case KeyCode.RShift:
                        rshift = wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN;     //is key down? otherwise false.
                        break;

                    case KeyCode.LShift:
                        lshift = wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN;     //is key down? otherwise false.
                        break;
                    }
                }
                else
                {
                    //todo sometimes when pressing modifier really quick, it may screw up, try using Control.Modifiers to determine the mods asap.
                    // problem is that it may be called half a sec later from the real press. and its so quick that only press down may be invoked here.
                    if (rctrl)
                    {
                        modifier |= ModKeys.RControl;
                    }
                    if (lctrl)
                    {
                        modifier |= ModKeys.LControl;
                    }
                    if (rshift)
                    {
                        modifier |= ModKeys.RControl;
                    }
                    if (lshift)
                    {
                        modifier |= ModKeys.LShift;
                    }
                    if (ralt)
                    {
                        modifier |= ModKeys.RAlt;
                    }
                    if (lalt)
                    {
                        modifier |= ModKeys.LAlt;
                    }
                }


                #endregion
                #region Args and Event firing

                //Console.WriteLine("(" + ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) ? "D" : "U") + ") " + modifier.ToString() + " + " + key.ToString());

                Hotkey          hotk = new Hotkey(key, modifier, null);
                HotkeyEventArgs args = null;
                //keydown
                if ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN))
                {
                    args = InvokeKeyDown(this, hotk);
                }
                else     //key up
                {
                    if ((wParam == WM_KEYUP || wParam == WM_SYSKEYUP))
                    {
                        args = InvokeKeyUp(this, hotk);

                        //if equals to last key event is up and equals to this key event -> KeyPress
                        // hotkey mode: /*tmp_key.CompareModifiers(key) && tmp_mods.CompareModifiers(modifier) && !(wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)*/
                        if (args == null || (args.Handled == false && presstags[(int)keyc]))
                        {
                            args = InvokeKeyPress(this, hotk);
                        }
                    }
                }



                /*if (args != null && args.Handled)
                 *      return 1;*/

                #endregion


                presstags[(int)keyc] = wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN;
#if DEBUG_KEYS
                Console.Clear();
                Console.WriteLine("RCTRL " + rctrl + " | " + "LCTRL " + lctrl + " | " + "RAlt " + ralt + " | " + "LAlt " + lalt + " | ");
                Console.WriteLine("RShift " + rshift + " | " + "LShift " + lshift);
                Console.WriteLine(Hotkey.Create(key, modifier, "").ToString());
#endif
            }
            if ((wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) && duplicatetags[(int)keyc] == false)
            {
                duplicatetags[(int)keyc] = true;
            }
            else if ((wParam == WM_KEYUP || wParam == WM_SYSKEYUP) && duplicatetags[(int)keyc] == true)
            {
                duplicatetags[(int)keyc] = false;
            }
        }