how do you keep a button assocaited with an application?

This is a tough one. I just made an application that is suppost to repond to the buttons F1 or F2 being pushed. It works great when the focus is set on the application. But, if I go to another app. it does not relay that button input to the application I made. So, is there a way to tell the entire computer to set the focus on an applcation when a button is pushed? so, if I push F1, it will run the script after it sets focus to the correct application?

kick ass!