#687 – What Happens If You Forget to Release The Mouse

A user interface element can capture the mouse, asking to receive all future mouse events, no matter where the mouse cursor is located.  You’ll typically capture the mouse in a mouse down or related event and then release the mouse in the corresponding mouse up event so that things go back to normal.

But what happens if something goes wrong and you forget to release the mouse?  At that point, the element that captured the mouse will continue to receive mouse input.  This means that other elements in your application that use the mouse will no longer function.

In the example below, the Raphael label captures the mouse on mouse down, but does not release it on mouse up.  Then when I click on the Button, the Raphael label is still getting the mouse events.

Advertisements