I believe there's an API function to retrieve the "foreground" window, whatever process it belongs to, so that you can always be sending keys to the right place.
Regardless, sounds like you got something working.
Just curious, though. Mame already had pretty good keyboard remapping capabilities. Was there a specific reason for not using that? or maybe you were looking for something more generic to work across a bunch of emulators?
Yes, I already use this function in the code... Still, it doesn't work.
But it does work with other programs - games (e.g. nestopia). With Pro evolution soccer...no. Same thing with most modern games. It doesn't work with MAME too
(it works only with version up to 0117).
I can explain it only like this:
You can send keystrokes only to the foreground window... Ok, this is what SendInput does
(you may need to bring the application to foreground, if it's not).
SendInput works with virtual keycodes
(e.g VK_RIGHT, which is the right arrow key and so on). Direct Input works in low level. So SendInput. Why it's not working then?
I wrote a small program, that used direct input, and then I tried to send keystrokes with SendInput, from another application. It did work!!!
However it's not working with games. It doesn't work even when you change the VK_ constants, with direct input DIK constants!
I am guessing, because direct input works at low level, it can scan for keystrokes from a different
(and background) process
(like windows hooks can do). Because that background proccess has no window handle, it's impossible to bring it at foreground (foreground has no meaning). SendInput is sending the keystrokes to the foreground window
(in our case the game you are playing) successfully... but there is no code there!!!
I know that mame has remapping capabilities. I am trying to create a more generic controller (like you said) and I don't want to use commercial controllers nor thirdparty remappers (freeware or shareware) and frontends. It's all about the "completely homemade" title of the thread
PS: I found out what to do with the old code... I will publish it for free (I mean, open it). After all, it's a working piece of code (with some limitations regarding the games only)
