You can use a script and the "control" console command (which doesn't work from the actual console, only the scripting console_command command). I believe there's a scripting tutorial in the Guides, Tutorials, and Tools section somewhere.

-Simetrical