How to detect toolbar button presses?

Hi,

do you know, how to solve these two problems properly?

1. I would like to catch the event when user presses a button or selects a menu item, before the selected function is started.

2. When user presses a button on my custom addin's toolbar, I need to cancel all ongoing commands somehow:

     a. If a property sheet is opened, close it programmatically.

     b. If a function is in progress (edit sketch, et.c) exit from that function to a state where no buttons are pressed (like it's the case right after SW start-up)

Any solution or hint would be appreciated.

Thank you.

SolidworksApi macros