GUI object not responding to left click
13 views (last 30 days)
Show older comments
I am trying to detect a left mouse click on a GUI object (specfically, edit and static Box) but it absolutely refuses to do it. I tried 4-5 different methods of coding presented here, but none of them works. Funny thing is, it recognises right click but no matter what I do, it won't recognize a left click. Either from the trackpad or a mouse connected to my Mac. It even recognises double click IF AND ONLY IF it is followed with a right click, then it prints both double click and right click simultaneously (it won't recognize double click on its own)
Here is the simplest way I tried to code (with many other ways) but all of them give the exact same output as mentioned above
seltype = get(gcf,'SelectionType')
if strcmpi(seltype,'Normal')
fprintf('left mouse button pressed!\n');
elseif strcmpi(seltype,'alt')
fprintf('right mouse button pressed!\n');
elseif strcmpi(seltype,'open')
fprintf('double mouse click!\n');
else
fprintf('other - shift and mouse-click!\n');
end
WHAT IS WRONG WITH MATLAB???? :'(
0 Comments
Answers (1)
Geoff Hayes
on 5 Jul 2016
Arnav - when I use the above code in the WindowButtonDownFcn callback for my figure (not the edit text box), then MATLAB has no problem in recognizing a left-click, right-click and double-click. On my MacBook, pressing the trackpad results in a left-click, pressing the ctrl button and the trackpad results in a right-click, and double-clicking the track pad is obvious. Note that you will still register a left- or right-mouse click prior to the double-click. This is expected behaviour and will let you know if you have double-clicked with left or right button.
I am running with R2014a and OS X 10.11.5.
1 Comment
See Also
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!