Keyboard & Program interaction

hi, how do i make the program type stuff automatically after listening to a keystroke on the keyboard?

for example, i press on the "right shift" button in notepad, and it'll type "hello world".

im thinking of doing a macro kinda thing; push one button, a heck of a lot buttons that i set gets pressed automatically.

what APIs are needed, and are there any examples?

thanks.
Last edited on
RegisterHotKey to set up a global hotkey. You'll receive a message whenever that hotkey is pressed even if your program is not in focus:

http://msdn.microsoft.com/en-us/library/ms646309(VS.85).aspx


GetForegroundWindow() to get an HWND to the active window:

http://msdn.microsoft.com/en-us/library/ms633505(VS.85).aspx


And PostMessage() to send that HWND messages:

http://msdn.microsoft.com/en-us/library/ms644944(VS.85).aspx


Note that I don't think any key combination can be a hotkey. So just trying to use right-shift as a key won't work -- it'd have to be Shift+X or something like that.

You can fall back to GetASyncKeyState() to check for keys like right shift, but that requires constant polling, rather than letting you get notified.
The right method is with Kbd Hook.
Plenty of samples in MSDN... (C)
ah... Visual C++ is totally new to me and im a Java programmer.
Topic archived. No new replies allowed.