the code that handles item clicking can be found
here, but that's probably not what you need, since you need to intercept the clicks on the button frames directly to avoid breaking stuff.
the easiest way to do it is to listen for a modified click, pre-hooking HandleModifiedItemClick shouldn't cause taint.
if you want to listen for simple raw clicks then it gets quite complicated, probably involving invisible secure overlay frames for every item button.