If you are operating at the X level (as in Gilles' question), then use xdotool like so:
xdotool key KEYSTROKE_SPECIFIER
Where KEYSTROKE_SPECIFIER can be something like "a" or "F2" or "control+j"
EDIT: I missed your response to Gilles' question, sorry. I'll leave this response here as a solution for the X-case.