Returning which button was pressed.

Hi guys, I have been looking for a while but cant seem to find an answer. If i use something like:
waitforbutttonpress
can I return the button which was pressed? for example:
button = waitforbuttonpress
if button == rightMouse
methodOne
elseif button == leftMouse
methodTwo
else
break
end

1 件のコメント

Sergey Lopatnikov
Sergey Lopatnikov 2017 年 2 月 19 日
It will not work. You cannot exit from loop this way. You only can start loop as one of the methods, However, if you start loop[ you will not be able to stop evaluation by mouse click because decision is outside the loop.

サインインしてコメントする。

 採用された回答

José-Luis
José-Luis 2012 年 10 月 26 日

0 投票

f = figure(1);
click_type=get(f,'SelectionType');
if strcmp(click_type,'normal') %right click
%Do some stuff
elseif strcmp(click_type,'alt') %left click
%Do some other stuff
end

4 件のコメント

Tim Mottram
Tim Mottram 2012 年 10 月 26 日
編集済み: Tim Mottram 2012 年 10 月 26 日
Ok, this looks like the sort of thing I need. Can you tell me if I need to use the figure as a reference? I.E does the click always have to be on that figure? Can I use some sort of general:
button = ButtonDown
instead?
Also, Will the code pause on the click_type statement or do I write:
f = figure(1);
waitforbuttonpress
click_type = get(f,'SelectionType');
??
José-Luis
José-Luis 2012 年 10 月 26 日
As far as I know, the click needs to be in the figure axes.
Tim Mottram
Tim Mottram 2012 年 10 月 26 日
Answered my own question. if you want it to wait you need waitforbuttonpress.
Tim Mottram
Tim Mottram 2012 年 10 月 26 日
This worked perfectly thanks for all your help :)

サインインしてコメントする。

その他の回答 (1 件)

Sachin Ganjare
Sachin Ganjare 2012 年 10 月 26 日

0 投票

1 件のコメント

Tim Mottram
Tim Mottram 2012 年 10 月 26 日
Thanks for the help, I'm not using a GUI but I'll have a look and see if I can modify something :).

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDesktop についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by