Hi,
I can send any windows application key strokes with PostMessage() api.But i cant send key strokes to Game window by using PostMessage.
Anyone know anything about using Direct Input functions for sending keys to games from C#.
Hi,
I can send any windows application key strokes with PostMessage() api.But i cant send key strokes to Game window by using PostMessage.
Anyone know anything about using Direct Input functions for sending keys to games from C#.
There is now way to do this via the DirectInput API.
The only way to archive the same effect would be to write your own DirectInput COM object which just wraps the normal DirectInput object. Afterwards you can add code to simulate keystrokes. The trick is to replace the Win32 dinput.dll with your version. All games will then load your DLL on startup.
I'm afraid that you can't do that from a managed language though. You have to do this with native code as it requirs quite a bit of low level hackery.
An alternate way would be to hook the DirectInput API directly - Microsoft Research has provided a library to do this already: http://research.microsoft.com/en-us/projects/detours/
Once you hook into the API, you can do whatever you want with it. However, it's worth noting that in recent versions of Windows, DirectInput for mouse & keyboard input is just a wrapper around the Win32 windows messages. DirectInput spawns a thread in the background and simply intercepts window messages before passing them along back to the application. It's one of the reasons why Microsoft no longer recommends the use of DirectInput - and it means that messaging APIs like PostMessage should work just fine.