Button boundaries

Hi,
How do i define boundaries to my buttons?
For example, if i press a button and drag the cursor out of its range, it continues to perform its operation even when technically im no longer pressing it.
I dont use widget, and i need the event to be touch and not tap…