private void Hooks_KeyDown(LLKHEventArgs e) { if (e.Keys == Keys.RControlKey) { ctrl_key = true; } if (e.Keys == Keys.PrintScreen) { if (!bsmooth) { if (ctrl_key) { smooth(); } else { screen(); } } } if (bsmooth) { if (e.Keys == Keys.Escape) { sm.Close(); bsmooth = false; } } }
private void Hooks_KeyUp(LLKHEventArgs e) { if (e.Keys == Keys.RControlKey) { ctrl_key = false; } }
/// <summary> /// Hook process messages. /// </summary> /// <param name="nCode"></param> /// <param name="wParam"></param> /// <param name="lParam"></param> /// <returns></returns> static IntPtr HookProcFunction(int nCode, IntPtr wParam, [In] IntPtr lParam) { if (nCode == 0) { LLKHEventArgs args = null; if (localHook) { bool pressed = false; if (lParam.ToInt32() >> 31 == 0) { pressed = true; } Keys keys = (Keys)wParam.ToInt32(); args = new LLKHEventArgs(keys, pressed, 0U, 0U); if (pressed) { if (KeyDown != null) { KeyDown(args); } } else { if (KeyUp != null) { KeyUp(args); } } } else { KBDLLHOOKSTRUCT kbd = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT)); bool pressed = false; if (wParam.ToInt32() == 0x100 || wParam.ToInt32() == 0x104) { pressed = true; } Keys keys = (Keys)kbd.vkCode; args = new LLKHEventArgs(keys, pressed, kbd.time, kbd.scanCode); if (pressed) { if (KeyDown != null) { KeyDown(args); } } else { if (KeyUp != null) { KeyUp(args); } } } if (args != null && args.Hooked) { return((IntPtr)1); } } return(API.CallNextHookEx(hHook, nCode, wParam, lParam)); }