You're looking for xdotool.
Code:
xdotool key "ctrl+alt+S" #simulate a button combination
xdotool type "Hello world!" #"type" a text string
xdotool click 3 #emulate a mouse click
There are also older options, like xmacroplay and xvkbd, but you don't want to use them. xdotool does it better.