Trap and modify input using a keyboard hook

  • Thread starter Thread starter Radu Stanciu
  • Start date Start date
R

Radu Stanciu

Hi,

Is there a way to modify the keyboard output? For example, I would like change the
"a" character to "b" when the user presses the key and my application is running.

I'm using a keyboard hook class, it can be found at
http://www.codeproject.com/csharp/globalhook.asp?msg=1033410. However, I haven't
found a way to change the output. I've searched the net for this but I've found
nothing usable. Do you have any idea how could this be accomplished (I know it's
possible since I saw other applications doing it)?

Thanks,

Radu Stanciu
 
This is one way I can think of doing it:

private void textBox1_KeyPress(object sender, KeyPressEventArgs e) {
if (e.KeyChar == char.Parse("a"))
e.KeyChar = char.Parse("b");
}

Of course you should provide a more intelligent way of determining the
key pressed and the replacement to use, but hopefully the example shows
the idea.

Hope it helps,
Jakob
 
Back
Top