Returning which button was pressed.

1 次查看(过去 30 天)
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
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
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
  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 :).

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by