What is the best way to toggle a mouse-driven UI overlay?

This works fine for setting the focus to the widget, Nick, thanks.
However, when I call ExitCursorMode the cursor remains visible and focus does not shift back to the viewport. Do you have any further suggestions?