예제 #1
0
 void Hook_KeyboardPressed(object sender, GlobalKeyHookEventArgs e)
 {
     if (e.VKeyCode == VKeyCode.F4)
     {
         if (GlobalKeyHook.IsKeyPressed(VKeyCode.LeftControl) && GlobalKeyHook.IsKeyPressed(VKeyCode.LeftAlt))
         {
             Close();
         }
     }
 }
예제 #2
0
        static void Hook_KeyboardPressed(object sender, GlobalKeyHookEventArgs e)
        {
            switch (e.VKeyCode)
            {
            case VKeyCode.LeftControl:
                switch (e.KeyboardState)
                {
                case VKeyState.KeyDown:
                    AllowControl = false;
                    break;

                case VKeyState.KeyUp:
                    AllowControl = true;
                    break;
                }
                break;
            }
        }
예제 #3
0
        public IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            bool fEatKeyStroke = false;

            var wparamTyped = wParam.ToInt32();

            if (Enum.IsDefined(typeof(VKeyState), wparamTyped))
            {
                object o = Marshal.PtrToStructure(lParam, typeof(LowLevelKeyInputArgs));
                LowLevelKeyInputArgs p = (LowLevelKeyInputArgs)o;

                var eventArguments = new GlobalKeyHookEventArgs(p, (VKeyState)wparamTyped);

                EventHandler <GlobalKeyHookEventArgs> handler = KeyboardPressed;
                handler?.Invoke(this, eventArguments);

                fEatKeyStroke = eventArguments.Handled;
            }

            return(fEatKeyStroke ? (IntPtr)1 : CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam));
        }