Modal Dialog Escape Button Click

Is there any way to get the outclicking or escape clicking of modal dialog as input for a callback? I need that to clean modal dialogs content.