void Hook_KeyboardPressed(object sender, GlobalKeyHookEventArgs e) { if (e.VKeyCode == VKeyCode.F4) { if (GlobalKeyHook.IsKeyPressed(VKeyCode.LeftControl) && GlobalKeyHook.IsKeyPressed(VKeyCode.LeftAlt)) { Close(); } } }
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; } }
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)); }