mouse button click
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
tomas
el 10 de Jun. de 2011
Respondida: Conny Fru
el 25 de Sept. de 2019
Hello, is it somehow possible to distinguish which mouse button was pressed, left or right?
Thank you
0 comentarios
Respuesta aceptada
Matt Tearle
el 10 de Jun. de 2011
The figure has a property 'SelectionType'. This will have the value 'normal' for a left-click, and 'alt' for a right-click.
For more, see the doc: MATLAB -> User's Guide -> HG Property Browser -> Figure -> SelectionType
Example:
function mybttnfcn(h,~)
hf = get(h,'parent');
b = get(hf,'selectiontype');
xy = get(gca,'CurrentPoint');
if strcmpi(b,'normal')
text(xy(1,1),xy(1,2),'Left click')
elseif strcmpi(b,'alt')
text(xy(1,1),xy(1,2),'Right click')
else
text(xy(1,1),xy(1,2),'Careful there, crazy man!')
end
Then try something like:
figure
plot(rand(5))
set(gca,'buttondownfcn',@mybttnfcn)
2 comentarios
roudan
el 9 de Nov. de 2017
wow, Matt Tearle, that is really helpful to me. I google it and find your post. Thanks
But I like to change 2D line plot to be 2D point plot and assign a value for each individual point, then extract the value for each point when clicking on the point, how to do that? I don't want to extract XY value. Thanks, I appreciate your help.
Más respuestas (2)
Ver también
Categorías
Más información sobre Graphics Object Properties en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!