From 21c19b43142ff21151774e5c57910c0b028d25cf Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Sun, 5 Dec 2021 21:38:18 -0600 Subject: [PATCH] Revert "Use Safe Delegate Instead" This reverts commit 5f9036568d53a01b6b0c64be94c3aeb0afad3028. --- Flow.Launcher.Infrastructure/Hotkey/GlobalHotkey.cs | 7 +++---- Flow.Launcher.Infrastructure/Hotkey/InterceptKeys.cs | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Hotkey/GlobalHotkey.cs b/Flow.Launcher.Infrastructure/Hotkey/GlobalHotkey.cs index 49efc91b8..5f14b7598 100644 --- a/Flow.Launcher.Infrastructure/Hotkey/GlobalHotkey.cs +++ b/Flow.Launcher.Infrastructure/Hotkey/GlobalHotkey.cs @@ -12,8 +12,8 @@ namespace Flow.Launcher.Infrastructure.Hotkey public unsafe class GlobalHotkey : IDisposable { private static readonly IntPtr hookId; - - private static InterceptKeys.LowLevelKeyboardProc _hookedKeyboardProc; + + public delegate bool KeyboardCallback(KeyEvent keyEvent, int vkCode, SpecialKeyState state); internal static Func hookedKeyboardCallback; @@ -26,9 +26,8 @@ namespace Flow.Launcher.Infrastructure.Hotkey static GlobalHotkey() { - _hookedKeyboardProc = LowLevelKeyboardProc; // Set the hook - hookId = InterceptKeys.SetHook(_hookedKeyboardProc); + hookId = InterceptKeys.SetHook(& LowLevelKeyboardProc); } public static SpecialKeyState CheckModifiers() diff --git a/Flow.Launcher.Infrastructure/Hotkey/InterceptKeys.cs b/Flow.Launcher.Infrastructure/Hotkey/InterceptKeys.cs index 1203eca42..7fec3c383 100644 --- a/Flow.Launcher.Infrastructure/Hotkey/InterceptKeys.cs +++ b/Flow.Launcher.Infrastructure/Hotkey/InterceptKeys.cs @@ -10,7 +10,7 @@ namespace Flow.Launcher.Infrastructure.Hotkey private const int WH_KEYBOARD_LL = 13; - public static IntPtr SetHook(LowLevelKeyboardProc proc) + public static IntPtr SetHook(delegate* proc) { using (Process curProcess = Process.GetCurrentProcess()) using (ProcessModule curModule = curProcess.MainModule) @@ -20,7 +20,7 @@ namespace Flow.Launcher.Infrastructure.Hotkey } [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] - public static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId); + public static extern IntPtr SetWindowsHookEx(int idHook, delegate* lpfn, IntPtr hMod, uint dwThreadId); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)]