Most Windows games use the DirectX API for reading keystrokes, they simply ignore that kind of key-pressing messages. They interact directly with the hardware. So your code won't work in the 99% of the Windows games out there.
I would achieve this by writing my own driver and send keystrokes like if they are being pressed manually. It's complex, but not impossible.
Also, I think there's a better way to achieve whatever you want to do. In most cases sending keystrokes it's not a clean solution (specially if you are trying to cheat).
Hope it helps.