I wanted to write a c++ code to emulate pressing a keyboard key \"A\":
// Set up a generic keyboard event.
ip.type = INPUT_KEYBOARD;
ip.ki.wScan = 0; // hard
If you are looking to create a game bot, have you looked at the program AutoHotKey? http://www.autohotkey.com/
It offers a scripting language, that allows you to do a lot of the tasks involved in 'bot' creation and it's rather easier than trying to do it all in C++
(It certainly played Farmville for me, when all my family pressured me into creating an account)