2

Alright, I want to write a program that intercepts mouse and keyboard events before they are reported to the active window/application, whatever that may be. Based on my program logic I want to be able to send custom key events.

For example: When the mouse button is held down, for any key press, send the next alphabetical letter. So if I hold down the right mouse button and hit 'a', the application sees it as a 'b' keypress.

I have briefly researched hooks and methods of intercepting WinAPI messages, and I'm unclear as to whether this is the solution I am looking for or not. According to what I've read, some of these solutions require you to inject a DLL into the desired application; my program needs to work for any running application.

Also, I have noticed that most of these solutions are in C#. As a matter of personal preference I would like to use C++ to write this program. Is there any reason why I would need to use C#?

Any pointers or advice is appreciated.

jsonnull
  • 415
  • 3
  • 12
  • The easy hook way is to use a low level hook, which doesn't require any dlls. – chris Dec 13 '12 at 05:24
  • I see. So if I use this hook to intercept mouse and keyboard messages, is there a way I can alter the message before I dispatch it back to the operating system and the active application? (e.g. change what letter is being pressed?) – jsonnull Dec 13 '12 at 05:31
  • Yes, you can return a positive value from your hook callback to block anything after from seeing it and use `SendInput` with what you really want to go out. – chris Dec 13 '12 at 05:34
  • 1
    I see. I'll give this a shot and see if I can get a prototype working. – jsonnull Dec 13 '12 at 05:42

0 Answers0