As for simulating the keypress, there's an easy way to do this using Applescript.
tell application "System Events"
keystroke "A"
end tell
(You might need to "enable access for assistive devices" in the Accessibility prefpane).
Alternatively, the same script can be run on the command line
osascript -e 'tell app "System Events" to keystroke "a"'
EDIT: If you're worried about speed, the scripting bridge can help.
#import <Foundation/Foundation.h>
#import <ScriptingBridge/ScriptingBridge.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
id sysEvents = [SBApplication applicationWithBundleIdentifier: @"com.apple.systemevents"];
[sysEvents keystroke: @"h" using: 'Ksft'];
[sysEvents keystroke: @"e" using: 0];
[sysEvents keystroke: @"l" using: 0];
[sysEvents keystroke: @"l" using: 0];
[sysEvents keystroke: @"o" using: 0];
// keyCode might be more suitable for your purposes
for (int i = 32; i < 64; i++)
{
[sysEvents keyCode: i using: 0];
}
}
}
You can find key codes using this app.