Fix Unexpected Intercept result when multiple plugin register the global hotkey event

This commit is contained in:
Kevin Zhang 2021-11-27 14:26:20 -06:00
parent 1c60b8e586
commit d3d1f6faa7
4 changed files with 30 additions and 6 deletions

View file

@ -79,7 +79,7 @@ namespace Flow.Launcher.Infrastructure.Hotkey
{
return InterceptKeys.CallNextHookEx(hookId, nCode, wParam, lParam);
}
return (IntPtr)1;
return (IntPtr)(-1);
}
public static void Dispose()

View file

@ -104,7 +104,21 @@ namespace Flow.Launcher.Plugin
/// Fired after global keyboard events
/// if you want to hook something like Ctrl+R, you should use this event
/// </summary>
[Obsolete("Unable to Retrieve correct return value")]
event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent;
/// <summary>
/// Register a callback for Global Keyboard Event
/// </summary>
/// <param name="callback"></param>
public void RegisterGlobalKeyboardCallback(Func<int, int, SpecialKeyState, bool> callback);
/// <summary>
/// Remove a callback for Global Keyboard Event
/// </summary>
/// <param name="callback"></param>
public void RemoveGlobalKeyboardCallback(Func<int, int, SpecialKeyState, bool> callback);
/// <summary>
/// Fuzzy Search the string with the given query. This is the core search mechanism Flow uses

View file

@ -40,7 +40,7 @@ namespace Flow.Launcher
_settingsVM = settingsVM;
_mainVM = mainVM;
_alphabet = alphabet;
GlobalHotkey.hookedKeyboardCallback += KListener_hookedKeyboardCallback;
GlobalHotkey.hookedKeyboardCallback = KListener_hookedKeyboardCallback;
WebRequest.RegisterPrefix("data", new DataWebRequestFactory());
}
@ -190,25 +190,35 @@ namespace Flow.Launcher
Arguments = FileName is null ?
explorerInfo.DirectoryArgument.Replace("%d", DirectoryPath) :
explorerInfo.FileArgument.Replace("%d", DirectoryPath).Replace("%f",
Path.IsPathRooted(FileName) ? FileName : Path.Combine(DirectoryPath, FileName))
Path.IsPathRooted(FileName) ? FileName : Path.Combine(DirectoryPath, FileName))
};
explorer.Start();
}
public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent;
private readonly List<Func<int, int, SpecialKeyState, bool>> _globalKeyboardHandlers = new();
public void RegisterGlobalKeyboardCallback(Func<int, int, SpecialKeyState, bool> callback) => _globalKeyboardHandlers.Add(callback);
public void RemoveGlobalKeyboardCallback(Func<int, int, SpecialKeyState, bool> callback) => _globalKeyboardHandlers.Remove(callback);
#endregion
#region Private Methods
private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state)
{
var continueHook = true;
if (GlobalKeyboardEvent != null)
{
return GlobalKeyboardEvent((int)keyevent, vkcode, state);
continueHook = GlobalKeyboardEvent((int)keyevent, vkcode, state);
}
foreach (var x in _globalKeyboardHandlers)
{
continueHook &= x((int)keyevent, vkcode, state);
}
return true;
return continueHook;
}
#endregion

View file

@ -300,7 +300,7 @@ namespace Flow.Launcher.Plugin.Shell
{
this.context = context;
_settings = context.API.LoadSettingJsonStorage<Settings>();
context.API.GlobalKeyboardEvent += API_GlobalKeyboardEvent;
context.API.RegisterGlobalKeyboardCallback(API_GlobalKeyboardEvent);
}
bool API_GlobalKeyboardEvent(int keyevent, int vkcode, SpecialKeyState state)