From 4a75773bc477770385630e058833ef9cd2d1bea8 Mon Sep 17 00:00:00 2001 From: nsnail Date: Tue, 20 Dec 2022 16:49:08 +0800 Subject: [PATCH] =?UTF-8?q?=20=E9=92=A9=E5=AD=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Native/KeyboardHook.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Native/KeyboardHook.cs b/src/Native/KeyboardHook.cs index 5338080..97459db 100644 --- a/src/Native/KeyboardHook.cs +++ b/src/Native/KeyboardHook.cs @@ -57,12 +57,14 @@ internal sealed class KeyboardHook : IDisposable private nint HookCallback(int nCode, nint wParam, nint lParam) { - if (nCode < 0 || wParam != Win32.WM_KEYDOWN) { - return Win32.CallNextHookEx(_hookId, nCode, wParam, lParam); + if (nCode >= 0 && wParam == Win32.WM_KEYDOWN) { + var hookStruct = (Win32.KbdllhooksStruct)Marshal.PtrToStructure(lParam, typeof(Win32.KbdllhooksStruct))!; + if (KeyUpEvent?.Invoke(null, hookStruct) ?? false) { + return -1; + } } - var hookStruct = (Win32.KbdllhooksStruct)Marshal.PtrToStructure(lParam, typeof(Win32.KbdllhooksStruct))!; - return KeyUpEvent?.Invoke(null, hookStruct) ?? false ? -1 : nint.Zero; + return Win32.CallNextHookEx(_hookId, nCode, wParam, lParam); } }