Controlling GUI from Shell Script

Hi Everybody,

I previously posted this under Unix for dummies and got no answers, so here goes again:

I'm trying to create a script that will launch firefox from a bash shell in ubuntu and perform certain tasks.
Why does it have to be a script? Because this firefox must eventually run in a server with xvfb (no gnome, no kde), so I will not have access to it through the GUI.
At this point I'm testing on a gnome desktop, so far launching firefox is no problem, additionally I've figured out how to perform all of the commands I need from the keyboard by means of tabs, control and alt key combinations.
My questions are:

  1. How do I script tabs, control-key and alt-key combinations in the first place?
  2. How do I script these so that they apply to the particular instance of firefox that was just launched?
    (Actually, Here doc block seems promising for question 2, but it does me no good if I can't answer question 1)

Any help / samples will be greatly appreciated