I'm looking for a way to simulate key pressing on Windows XP. I have a program that can recognize my voice, and I want to map the voice command to some keys on the keyboard. For example, when playing games, by saying "map" the program can bring up the in-game map.
I'm working with VC++ 2005 and I've tried both keybd_event and SendInput functions, but they are just too weak. By weak I mean they work in some games(e.g. World of Warcraft), but fail to work in the others(e.g. Neverwinter Nights, by saying "map" it won't bring up the map like it was in WoW, but by directly pressing the key 'm' it works.).
I've tried to use SetForegroundWindow() but it doesn't seem to affect anything.
I use mouse_event() function to simulate the mouse event based on the voice command, and it works fine for pretty much all games that I have tested(without using SetForegroundWindow()). However when I speak a voice command that suppose to simulate a key press it doesn't not work for all games.
Any idea why?
The structure of my speech recognition code looks like:
I'm wondering if there are other ways of simulating keyboard events?
void SRHandler::initEngine(LPCWSTR gramFile)
//-------initialize Speech Application Programming Interface -----//
void SRHandler::processRecoEvent(HWND hWnd)
//-------if voice command is recognized ---//
void SRHandler::executeCommand(ISpPhrase *pPhrase, HWND hWnd)
//call functions such as SendInput to simulate keyboard event or use mouse_event() to simulate mouse event