GUI object not responding to left click
14 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Geoff Hayes
2016-7-5
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!