I started using MouseKeyHook library couple of days ago to intercept keyboard buttons for an application that we're building (the application uses numerical keyboard as input to send specific messages through Akka, etc).
I've managed to get it to work pretty quickly using a console app and registering everything there, but once I moved the implementation into a specific service, it stopped working (event is not being fired).
Here's the code example:
public class KeypadService : IKeypad
{
private readonly IKeyboardEvents _keyboardEvents;
public KeypadService()
{
_keyboardEvents = Hook.GlobalEvents();
_keyboardEvents.KeyPress += GlobalHookKeyPress;
}
public void Enable(Action<string> codeEntered)
{
}
public void Disable()
{
_keyboardEvents.KeyPress -= GlobalHookKeyPress;
}
private static void GlobalHookKeyPress(object sender, KeyPressEventArgs e)
{
// Do something
}
}
KeypadService is created by Autofac at the start of the application (and the startup application is a console app).
builder.RegisterType<KeypadService>().As<IKeypad>().SingleInstance();
The constructor is being hit and everything executes inside the constructor.
Any clue as to why it might not be firing? Any help is appreciated!