views:

278

answers:

3

I'm wondering if its possible to make a program in C++ that can "press" keys, or make the computer think certain keys have been pressed, and do things like make a program that "plays" games, or automatically enter some long and obscure button sequence that no one could remember.

(I can't think of any right now, but savegame passwords might be an example, especially when you can't just type it, but have to move a cursor to the letter you want, then press enter or something).

Just wondering.

A: 

Lookup the CallNextHookEx function in the MSDN documentation.

eduffy
A: 

RaymondC suggests that this is a bad idea in general:

http://blogs.msdn.com/oldnewthing/archive/2005/05/30/423202.aspx

If you really want to make a convincing keyboard, you have to write a device driver that pretends to be a keyboard. In a pinch though, or if you're writing testing code, SendInput will do it.

Paul Betts