How to filter inputs from keyboard in all windows applications while our written code is running and lives in notification area
it's like: user opens our application, now when typing in for example MS Wo开发者_JAVA技巧rd, when he types "s" it is said in our code to filter "s" and change it to "M" so if he press "s" on keyboard, "M" is typed in MS Word document.
is it possible at all?
You should use low-level hook:
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr SetWindowsHookEx(int idHook,
LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool UnhookWindowsHookEx(IntPtr hhk);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode,
IntPtr wParam, IntPtr lParam);
And do what you want in your own hook implementation.
精彩评论