Closed jupagose closed 9 months ago
Hi! Thanks for asking!
Regarding the first question - the hooks are global, so they will work whether your app is in the foreground or not. If you want to listen to keyboard events only when your app is in the foreground, then you should use MAUI-specific tools for that (I can't help you with that since I've never worked with MAUI). I'm sure MAUI has something like OnKeyDown
and OnKeyUp
for window objects. If MAUI doesn't provide such functionality, then you should check whether the app is in the foreground inside event handlers.
Regarding the second question - the global hooks always listen to both keyboard and mouse events, you can't disable the mouse hook, but you don't need to create event handlers for all events.
Thanks for answer.
I implemented hookservice added Paused property to it and in my mainwindow events OnAcivated an OnDeactivated handle Paused property of my service.
About just listen keyboard is about in debug mode some times mouse move over my app becomes very very slow after 20-30 secones everythig gets normal.
Glad to hear that you've made it work! Regarding the second point - yeah, this is a known issue which cannot be fixed because of the way Windows handles global hooks.
Hi @jupagose! I've recently released version 5.3.0 which adds a way to disable the mouse hook and only listen to keyboard events. It can be done like this for example (it's available for all hook types):
var hook = new TaskPoolGlobalHook(GlobalHookType.Keyboard);
This way when you call hook.Run()
or hook.RunAsync()
a mouse hook won't even be created, and your mouse cursor won't freeze when debugging an event handler.
Great news. I'm going to try it.
I use your great tool in .net maui windows app but I'm facing some issues due when the user go to another app my app still listening keyboard.
Another question, there is a way to disable mouse listening ? I only need kb.
Thanks