First thing you need to realize is: you either need to give up the idea of replacement of anything from the input control, or otherwise give up the idea of affecting all possible applications. Just forget one or another. Say, you type OOK, but actually, you type O, then another O, then K, and then want to replace all three with $. Too late. You can type something processing some key strokes, but it you have already types three characters, they are already there. You cannot expect that you input anything in a window which can be accesses with
WM_SETTEXT/WM_GETTEXT
. You cannot expect that it is a Windows window object at all. Whole WPF application does not have any except main window. And you cannot simulate backspace: you are talking about any arbitrary application, but such application can be totally custom and simply ignore some key presses or interpret them in a different way.
So, the scenario you described in impossible in principle. All you can count of it your own application. It could collect some information on key strokes and not output them. It, say could collect "OO", but output it only when you add "K". If you add some other character, it will output all three at once. Needless to say, it would be quite confusing to the users.
The second thing you would need to forget about is using pure .NET. Whatever you do, you would need to use at least some native (unmanaged) software development, which you can combine with .NET using P/Invoke and/or C++/CLI.
You apparently need to invent something else. First thing which comes to mind is Windows Input Method Editors (IME). But I don't know your set of OS you want to support. Anyway, to get an idea, please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/hh848069%28v=vs.85%29.aspx[
^],
http://code.msdn.microsoft.com/windowsdesktop/Input-Method-Editor-IME-b1610980[
^],
http://msdn.microsoft.com/en-us/library/windows/apps/hh967425.aspx[
^],
find some more:
http://bit.ly/1azes7b[
^].
You can also develop some custom application which you should start and stop, processing raw system-wide keyboard events system-wide, and you can develop a way to enable/disable this processing.
First part of Windows API you would need is
Windows Hooks. Please see my past answers for further detail:
Creating global shortcuts.[
^],
How to set a window hook in other application?[
^],
How the Keyboard Hook works and how it is being implemented[
^].
Pay attention for my explanations related to collaboration between .NET and native code, P/Invoke and C++/CLI. This is what you always would need. For the output part of the solution, too. To simulate any kind of keyboard input, you would need to use raw Windows method
SendInput
:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310%28v=vs.85%29.aspx[
^],
in .NET via P/Invoke:
http://www.pinvoke.net/default.aspx/user32.sendinput[
^].
Overall, I would strongly discourage you to implement any of your idea. Perhaps I could give you a better advice if I knew your ultimate goal.
—SA