Hooking Keystrokes
Hello, I'm trying to create an application for real-time keystroke modification. The idea is to intercept keystrokes in real-time, and then replace their values with other predefined characters.
While I can hook keystrokes to determine what the user presses, I don't know how to modify the keystrokes before they reach the application. Is this even possible in C#, and if so, how?
P.S. : I realize that there is potential for someone to use this information in hack attempts, but frankly, there are other ways of messing up computers. I assure you, my intentions are benevolent.
SebastianPosted Jul 21, 2008, 3:42 PM
AlanPosted Jul 21, 2008, 2:31 PM
I don't know how you're currently hooking keystrokes but there's a fairly recent Code Project article which shows how to do this in a simple way using C#:
http://www.codeproject.com/KB/cs/CSLLKeyboardHook.aspx
Now, using this approach, it's easy enough to cancel the key by setting e.Handled to true in the eventhandler.
Provided the key you want to replace it with is to be sent to whatever application/control currently has the focus you could then use SendKeys.Send (or the API functions keybd_event or SendInput) to do this.
Is this what you had in mind?
SebastianPosted Jul 20, 2008, 8:55 PM
SebastianPosted Jul 20, 2008, 3:19 PM