detecting text input elements

I was wondering if it is possible to detect when a user clicks on a text entry field in any application they may have running.

-I know that “any application” is not possible, but how about any scriptable application.
-The script to detect this would be almost entirely contained within an on idle.
-When someone clicks on a box an icon (tiny borderless window) would pop up next to the text box.

pseudo code:

get the front window
on mouse entered theObject
if theObject is any text field or secure text field
show window "popup’
on click of the popup
run something
end if
end on mouse entered

I guess my question is…is there a way to detect any text box being clicked on. Or will I have a long “or” joined “if” statement for many possibilities?