Recording UI elements from X to an application



Hi,
I was wondering what the easiest or best method for getting/trapping
the UI elements sent to an application by X. For example, if I was
running firefox, I would like to trap, record and transfer all the UI
elements( mouse clicks, etc) that are sent to firefox by X.
[This is part of an effort to understand the various responses
triggered by UI events by an application - with out actually having to
look at its event handlers etc. i.e If I know what sort of events X is
providing the application, and the responses triggered in the
application, I will have some idea of the correlation]
Thanks,

.