I currently am able capture keyboard inputs while the program is not in focus using this solution.
Using global keyboard hook (WH_KEYBOARD_LL) in WPF / C#
I however want to know whether it is possible to stop other applications from using the input if it matches certain criteria, I would like to use it to capture bar-codes into my program while it runs in the background, but if you are working in notepad, the bar-code should preferably not be typed there as well.
I've added the following but the characters are still added to notepad as well.
if (nCode >= 0)
{
if (wParam == (IntPtr)InterceptKeys.WM_KEYDOWN)
{
int vkCode = Marshal.ReadInt32(lParam);
RawKeyEventArgs rk = new RawKeyEventArgs(vkCode, false);
if (KeyDown != null)
KeyDown(this, rk);
if (rk.isHandled)
{
return (IntPtr)0;
}
}
}
return InterceptKeys.CallNextHookEx(hookId, nCode, wParam, lParam);
Is the return supposed to be something different?