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?