0

Lately I was playing with Windows native functions RegisterHotKey and SendInput, trying to change Y into Z and similar. I know this is not the best way to modify keyboard input, it is just an exercise. It worked well for swapping 1 key for a different singular key. But then I tried something more complex.

I wanted to listen for shortcut: Shift + Left Alt + 2 and execute Right Alt + V. It didn't work as expected because I ended up with both left and right Alt being pressed at the same time so it did a paste command instead of @. The problem is that the hotkeys were also generating inputs that mixed with my synthetized input.

Can I intercept and modify the character before OS sends it to my foreground application at a deeper level?

While writing this, I found the GetMessage function. Could I hook it to solve this problem and modify the MSG struct?

I found a working example of how to hook a similar function in C# here, but I was unable to modify the structs that IntPtr was pointing to. Was I supposed to create my own struct and change pointer to point to it?

miran80
  • 945
  • 7
  • 22
  • Does this answer your question? [C# very simple keyboard hook](https://stackoverflow.com/questions/4928169/c-sharp-very-simple-keyboard-hook) –  Apr 17 '20 at 23:36
  • 1
    @MickyD keyboard hooks look for a single key press. OP wants to translate four simultaneous key presses into an entirely different structure, so no that link does not answer the question. A hook may be the way to go though - indeed [OP linked to one in the question](https://stackoverflow.com/questions/17579658/how-to-intercept-all-the-keyboard-events-and-prevent-losing-focus-in-a-winforms) – stuartd Apr 18 '20 at 00:19

0 Answers0