I feel like answered an identical question a couple of days ago. You wrap a button in a user widget and override:
There’s also Focus Lost event.
You then use those buttons in your interface. Since every button now has this, there’s little else to worry about.
edit: cross-posted with @Supremative