Interceptor
Interceptor copied to clipboard
Unloading From Event Handler
If I want to listen to a key press and unload on that key press, how do I go about it?
Unload()
hangs when executing within the EventHandler.
/cc @jasonpang
Continue'd Info: I was trying to unload on specific key press to disable / enable keyboard listening.
As for why Unload() is hanging, if mousefiltermode is not set to none, Unload will hang because there is a thread that this API uses and for whatever reason the program cannot terminate that thread.
Also, you cannot change keyboard/mousefilter modes after the Load() method has been called.
Now that saying, you can simply use the Keypress event which is offered by this API, and then using a simple if statement, check if the key pressed matches the key want to detect, if it does, just call the unload() method.
@Jamisco I was using an event handler on the key press event. I wasn't configuring mouse at all, so I'll have to check on that. I ended up making it a UI application with a click-able button to load/unload which worked fine, though I'd like to create a hot key to Load/Unload.
Regarding mouse listeners, are you saying that using them, there will be threads that never end even after application closes? I didn't get a chance to check this.
First, off to answer your main question
` Input InputDispenser = new Input(); InputDispenser.KeyboardFilterMode = KeyboardFilterMode.All; InputDispenser.MouseFilterMode = MouseFilterMode.None; InputDispenser.Load();
private void InputDispenser_OnKeyPressed(object sender, KeyPressedEventArgs e)
{
if (e.Key == Keys.F)
{
if(InputDispenser.IsLoaded)
{
InputDispenser.Unload();
}
else
{
InputDispenser.Load();
}
InputDispender.Unload();
}
}`
This should work, I dont see any reason as to why it shouldnt
Regarding the moust listeners, Yes that is my experience. There seems to be an unstoppable thread which cannot be terminated even when you close the program and or visual studio all together. The thread randomly hijacks mouse functions and if you want your mouse back, you have to restart the computer. Atleast that has been my experience thus far