Ejemplo n.º 1
0
        private static IntPtr KeyboardProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode == Win32Api.HC_ACTION)
            {
                var wParamValue = (uint)wParam;
                var lParamValue = (long)lParam;

                if (wParamValue == 256)
                {
                    var keyboardParam = (Win32Api.KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(Win32Api.KBDLLHOOKSTRUCT));

                    KeyClickEvent?.Invoke(keyboardParam.vkCode);
                }

                // 229 ( 0xE5 ) : VK_PROCESSKEY ( IME PROCESS key )
                if ((wParamValue == 229 && lParamValue == -2147483647) || (wParamValue == 229 && lParamValue == -2147483648))
                {
                    if (IsHookingArea())
                    {
                        return((IntPtr)1);
                    }
                }
            }

            return(Win32Api.CallNextHookEx(_keyboardId, nCode, wParam, lParam));
        }
Ejemplo n.º 2
0
        private IntPtr HookCallback(
            int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode < 0)
            {
                return(CallNextHookEx(_hookID, nCode, wParam, lParam));
            }

            if ((int)wParam == WH_KEYDOWN)
            {
                Keys key = (Keys)Marshal.ReadInt32(lParam);
                if (keyDown.TryGetValue(key, out startDelegate start))
                {
                    start();
                    return((IntPtr)1);
                }
                if (startApps.ContainsKey(key) && win_pushed ||
                    form.Visible)
                {
                    return((IntPtr)1);
                }
            }
            if ((int)wParam == WH_KEYUP)
            {
                Keys key = (Keys)Marshal.ReadInt32(lParam);
                if (keyUp.TryGetValue(key, out startDelegate start) && !start())
                {
                    return((IntPtr)1);
                }
                else if (startApps.TryGetValue(key, out KeyEventHandler app) && win_pushed)
                {
                    app();
                    return((IntPtr)1);
                }
                if (form.Visible)
                {
                    KeyClickEvent?.Invoke(key);
                    return((IntPtr)1);
                }
            }

            return(CallNextHookEx(_hookID, nCode, wParam, lParam));
        }
Ejemplo n.º 3
0
 void Update()
 {
     if (Input.GetKey(_keyCode))
     {
         if (_keyboardClickTime <= 0)
         {
             _keyDownEvent.Invoke();
         }
         _keyboardClickTime += Time.deltaTime;
         _keyClickEvent.Invoke(_keyboardClickTime);
     }
     else
     {
         if (_keyboardClickTime > 0)
         {
             _keyUpEvent.Invoke(_keyboardClickTime);
         }
         _keyboardClickTime = 0;
     }
 }