Bash: Exiting while true loop when terminal is not the focus window

I am running an Ubuntu Gutsy laptop with Advanced Compiz fusion options enabled. I am using xdotool to simulate keyboard input in order to rotate through multiple desktops.

I am looking for a way to kill a while true loop when the Enter key (or Control+C if it is easier) is pushed when the terminal window is not the focus window. The following script works like a charm if the terminal is the focus but I'm don't want a terminal window in the rotation.

Any ideas?

Here is the code.

#!/bin/bash

while true;
do
read -t 12 && break
./xdotool key "super+e"
read -t 2 && break
./xdotool key "Right"
read -t 2 && break
./xdotool key "super+e"
read -t 12 && break
./xdotool key "super+e"
read -t 2 && break
./xdotool key "Down"
read -t 2 && break
./xdotool key "super+e"
read -t 12 && break
./xdotool key "super+e"
read -t 2 && break
./xdotool key "Left"
read -t 2 && break
./xdotool key "super+e"
read -t 12 && break
./xdotool key "super+e"
read -t 2 && break
./xdotool key "Up"
read -t 2 && break
./xdotool key "super+e"

done

:smiley: I just read over my post, my "but I'm don't want" made me giggle internally.

I am assuming that this is much more trouble than it is worth.