Search code examples
c#.netwinformssendkeysactive-window

Send key to active window


Hey. I don't know if this is possible, but worth a shot. Say there's a third party racing game which doesn't use the mouse. Is there a way for me to create a Windows Form app which listens for mouse clicks and transfers a corresponding key to the game/active window (e.g. Left click would send the 'Up arrow' key to accelerate the Right click would decelerate by sending the 'Down arrow' key). I've looked at the SendKeys method, but it doesn't work once the game becomes the active window. Any ideas? Thanks


Solution

  • if the game uses DirectInput for reading the keys, then SendKeys wont work, as DI works at driver level, and SendKeys/SendInput works at API level, which may be too 'high' for the game to see. you can Hook into DirectInput, and send it commands, but its not going to be a one liner, and if you're new to DirectX, you're not going to find it fun.