Borrar filtros
Borrar filtros

Returning which button was pressed.

4 visualizaciones (últimos 30 días)
Tim Mottram
Tim Mottram el 26 de Oct. de 2012
Comentada: Sergey Lopatnikov el 19 de Feb. de 2017
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 comentario
Sergey Lopatnikov
Sergey Lopatnikov el 19 de Feb. de 2017
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.

Iniciar sesión para comentar.

Respuesta aceptada

José-Luis
José-Luis el 26 de Oct. de 2012
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 comentarios
Tim Mottram
Tim Mottram el 26 de Oct. de 2012
Answered my own question. if you want it to wait you need waitforbuttonpress.
Tim Mottram
Tim Mottram el 26 de Oct. de 2012
This worked perfectly thanks for all your help :)

Iniciar sesión para comentar.

Más respuestas (1)

Sachin Ganjare
Sachin Ganjare el 26 de Oct. de 2012
  1 comentario
Tim Mottram
Tim Mottram el 26 de Oct. de 2012
Thanks for the help, I'm not using a GUI but I'll have a look and see if I can modify something :).

Iniciar sesión para comentar.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by