I've never done anything of this sort, but I think that it may be achievable by using an AWTEventListener.

More on the AWTEvent parameter object can be found here. Also check here in the section...