Groups | Blog | Home
all groups > dotnet windows forms > february 2005 >

dotnet windows forms : Trap and modify input using a keyboard hook



Radu Stanciu
2/21/2005 3:21:16 AM
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,

Jakob Bengtsson-Jensen
2/21/2005 7:46:25 PM
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

[quoted text, click to view]
AddThis Social Bookmark Button