private IntPtr KeyboardHookDelegate(int code, IntPtr wParam, IntPtr lParam) { if (code < 0) { return(WindowsHookHelper.CallNextHookEx( keyBoardHandle, code, wParam, lParam)); } KeyBoardKeyPressed?.Invoke(this, new EventArgs()); return(WindowsHookHelper.CallNextHookEx( keyBoardHandle, code, wParam, lParam)); }
private IntPtr KeyboardHookDelegate(Int32 Code, IntPtr wParam, IntPtr lParam) { if (Code < 0) { return(WindowsHookHelper.CallNextHookEx(keyBoardHandle, Code, wParam, lParam)); } var pressedKey = GetKeyCode(lParam); KeyBoardKeyPressed?.Invoke(this, new KeyboardEventArgs(pressedKey)); return(WindowsHookHelper.CallNextHookEx(keyBoardHandle, Code, wParam, lParam)); }
private IntPtr KeyboardHookDelegate(Int32 Code, IntPtr wParam, IntPtr lParam) { if (Code >= 0) { int vkCode = Marshal.ReadInt32(lParam); KeyBoardKeyPressed?.Invoke(this, new CharArgs() { Key = (VirtualKeys)vkCode, Event = (KeyEvents)wParam }); } return(WindowsHookHelper.CallNextHookEx(keyBoardHandle, Code, wParam, lParam)); }
private IntPtr KeyboardHookDelegate(Int32 Code, IntPtr wParam, IntPtr lParam) { if (Code < 0) { return(DLLImport.CallNextHookEx( keyBoardHandle, Code, wParam, lParam)); } Console.WriteLine($"Code: {Code}, WP: {wParam}, LP: {lParam}"); KeyBoardKeyPressed?.Invoke(this, new KBArgs { Code = Code, WParam = wParam, LParam = lParam }); return(DLLImport.CallNextHookEx(keyBoardHandle, Code, wParam, lParam)); }
private IntPtr KeyboardHookDelegate( int Code, IntPtr wParam, IntPtr lParam) { if (Code < 0) { return(WindowsHookHelper.CallNextHookEx( keyBoardHandle, Code, wParam, lParam)); } var hookStruct = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT)); if (wParam == (IntPtr)0x0100 || wParam == (IntPtr)0x0104) //KeyDown { Keys key = (Keys)hookStruct.vkCode; if (key == Keys.LControlKey || key == Keys.RControlKey) { key = Keys.ControlKey; if (modifiers.HasFlag(Keys.Control)) { return(WindowsHookHelper.CallNextHookEx( keyBoardHandle, Code, wParam, lParam)); } } else if (key == Keys.LMenu || key == Keys.RMenu) { key = Keys.Menu; if (modifiers.HasFlag(Keys.Alt)) { return(WindowsHookHelper.CallNextHookEx( keyBoardHandle, Code, wParam, lParam)); } } else if (key == Keys.LShiftKey || key == Keys.RShiftKey) { key = Keys.ShiftKey; if (modifiers.HasFlag(Keys.Shift)) { return(WindowsHookHelper.CallNextHookEx( keyBoardHandle, Code, wParam, lParam)); } } KeyBoardKeyPressed?.Invoke(this, new KeyEventArgs(key | modifiers)); if (key == Keys.ControlKey) { modifiers |= Keys.Control; } else if (key == Keys.Menu) { modifiers |= Keys.Alt; } else if (key == Keys.ShiftKey) { modifiers |= Keys.Shift; } else if (key == Keys.Delete && modifiers.HasFlag(Keys.Control) && modifiers.HasFlag(Keys.Alt)) { modifiers &= ~Keys.Control; modifiers &= ~Keys.Alt; } } else if (wParam == (IntPtr)0x0101 || wParam == (IntPtr)0x0105) //KeyUp { Keys key = (Keys)hookStruct.vkCode; if (key == Keys.LControlKey || key == Keys.RControlKey) { modifiers &= ~Keys.Control; } else if (key == Keys.LMenu || key == Keys.RMenu) { modifiers &= ~Keys.Alt; } else if (key == Keys.LShiftKey || key == Keys.RShiftKey) { modifiers &= ~Keys.Shift; } } return(WindowsHookHelper.CallNextHookEx( keyBoardHandle, Code, wParam, lParam)); }