Revert "Use Safe Delegate Instead"

This reverts commit 5f9036568d.
This commit is contained in:
Kevin Zhang 2021-12-05 21:38:18 -06:00
parent ec96028f55
commit 21c19b4314
2 changed files with 5 additions and 6 deletions

View file

@ -13,7 +13,7 @@ namespace Flow.Launcher.Infrastructure.Hotkey
{ {
private static readonly IntPtr hookId; private static readonly IntPtr hookId;
private static InterceptKeys.LowLevelKeyboardProc _hookedKeyboardProc;
public delegate bool KeyboardCallback(KeyEvent keyEvent, int vkCode, SpecialKeyState state); public delegate bool KeyboardCallback(KeyEvent keyEvent, int vkCode, SpecialKeyState state);
internal static Func<KeyEvent, int, SpecialKeyState, bool> hookedKeyboardCallback; internal static Func<KeyEvent, int, SpecialKeyState, bool> hookedKeyboardCallback;
@ -26,9 +26,8 @@ namespace Flow.Launcher.Infrastructure.Hotkey
static GlobalHotkey() static GlobalHotkey()
{ {
_hookedKeyboardProc = LowLevelKeyboardProc;
// Set the hook // Set the hook
hookId = InterceptKeys.SetHook(_hookedKeyboardProc); hookId = InterceptKeys.SetHook(& LowLevelKeyboardProc);
} }
public static SpecialKeyState CheckModifiers() public static SpecialKeyState CheckModifiers()

View file

@ -10,7 +10,7 @@ namespace Flow.Launcher.Infrastructure.Hotkey
private const int WH_KEYBOARD_LL = 13; private const int WH_KEYBOARD_LL = 13;
public static IntPtr SetHook(LowLevelKeyboardProc proc) public static IntPtr SetHook(delegate*<int, UIntPtr, IntPtr, IntPtr> proc)
{ {
using (Process curProcess = Process.GetCurrentProcess()) using (Process curProcess = Process.GetCurrentProcess())
using (ProcessModule curModule = curProcess.MainModule) using (ProcessModule curModule = curProcess.MainModule)
@ -20,7 +20,7 @@ namespace Flow.Launcher.Infrastructure.Hotkey
} }
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] [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*<int, UIntPtr, IntPtr, IntPtr> lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]