MATLAB: In a callback, how to determine which mouse button was pressed to generate the callback

clicksdouble clickdoubleclickeventsMATLAB

I would like to determine, in a callback, which mouse button was pressed to generate the callback.

Best Answer

You can determine which mouse event has occurred by examining the 'SelectionType' property of the figure. The property can take the following values:
1. normal: left mouse button
2. extend: right mouse button on a 2-button mouse;
middle mouse button on a 3-button mouse
3. alt: left+right buttons on a 2-button mouse;
right mouse button on a 3-button mouse
4. open:double mouse click
For example, you can see the values taken by executing the following:
figure;
set(gcf,'WindowButtonDownFcn', 'disp(get(gcf,''SelectionType''));');
Now click in the current figure to see the values displayed.