Exemplo n.º 1
0
 private Boolean OnKeyUp(AppleKeyboardKeys appleKeyState, Keys key, Win32.KeyboardHookEventStruct keyEventStruct)
 {
     if (KeyUp != null)
     {
         AppleKeyboardEventArgs eArgs = new AppleKeyboardEventArgs(appleKeyState, key, keyEventStruct);
         KeyUp(this, eArgs);
         return(eArgs.Handled);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 2
0
        private IntPtr KeyboardHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            Win32.KeyboardHookEventStruct keyEventStruct = (Win32.KeyboardHookEventStruct)Marshal.PtrToStructure(lParam, typeof(Win32.KeyboardHookEventStruct));
            //Debug.WriteLine(String.Format("{0}, {1}, {2}", nCode, wParam, lParam));
            Debug.WriteLine(keyEventStruct);

            switch ((Keys)keyEventStruct.wVk)
            {
            case Keys.LShiftKey:
            case Keys.RShiftKey:
            case Keys.LMenu:
            case Keys.RMenu:
            case Keys.LControlKey:
            case Keys.RControlKey:
                return(Win32.CallNextHookEx(_hHook, nCode, wParam, lParam));
            }

            // 自分が投げたものは無視する
            if (keyEventStruct.dwExtraInfo != (IntPtr)0x37564)
            {
                Boolean handled = false;
                switch ((Int32)wParam)
                {
                case Win32.WM_KEYUP:
                    handled = OnKeyUp(CurrentKeyState, Keys.None, keyEventStruct);
                    break;

                case Win32.WM_KEYDOWN:
                    handled = OnKeyDown(CurrentKeyState, Keys.None, keyEventStruct);
                    break;
                }
                if (handled)
                {
                    return((IntPtr)1);
                }

                if ((CurrentKeyState & AppleKeyboardKeys.Fn) == AppleKeyboardKeys.Fn)
                {
                    if ((Int32)wParam == Win32.WM_KEYDOWN || (Int32)wParam == Win32.WM_SYSKEYDOWN)   // KEYDOWN
                    {
                        OnFnKeyCombinationDown(CurrentKeyState, (Keys)keyEventStruct.wVk, keyEventStruct);
                    }
                    //else if ((Int32)wParam == Win32.WM_KEYUP || (Int32)wParam == Win32.WM_SYSKEYUP) // KEYUP
                    //    OnFnKeyCombinationUp(CurrentKeyState, (Keys)keyEventStruct.wVk, keyEventStruct);
                    return((IntPtr)1);
                }
            }
            return(Win32.CallNextHookEx(_hHook, nCode, wParam, lParam));
        }
 public AppleKeyboardEventArgs(AppleKeyboardKeys appleKeyState, Keys key, Win32.KeyboardHookEventStruct keyEventStruct)
 {
     AppleKeyState = appleKeyState;
     Key = key;
     KeyEventStruct = keyEventStruct;
 }
Exemplo n.º 4
0
 private void OnFnKeyCombinationDown(AppleKeyboardKeys appleKeyState, Keys key, Win32.KeyboardHookEventStruct keyEventStruct)
 {
     if (FnKeyCombinationDown != null)
     {
         FnKeyCombinationDown(this, new AppleKeyboardEventArgs(appleKeyState, key, keyEventStruct));
     }
 }
 public AppleKeyboardEventArgs(AppleKeyboardKeys appleKeyState, Keys key, Win32.KeyboardHookEventStruct keyEventStruct)
 {
     AppleKeyState  = appleKeyState;
     Key            = key;
     KeyEventStruct = keyEventStruct;
 }