And to the original poster: I doubt that it's
particularly easy to do, and it's certainly platform
dependent. You'd pretty much have to go through the
window system: at best, you'd be able to ask "which
process has the input focus?"; at worst, you'd have
to have the target process send yours a message when
it receives (and loses) focus.
I hope there's an easier, cleaner way, but I don't
know of one.