Borrar filtros
Borrar filtros

App designer button down callback with keypress

15 visualizaciones (últimos 30 días)
Neurolab
Neurolab el 12 de Mzo. de 2024
Comentada: Neurolab el 12 de Mzo. de 2024
I am designing a small app using the Matlab app designer. I have a problem for which I have not been able to find a solution online.
I have an Axis in my app, I have set up a button down callback function, so that the user can click on the axis and select an object plotted there (the object plotted closest to the mouse click location). This works perfectly.
However, I would like the user to be able to hold the shift key and then select multiple objects in the axis. The problem is that I cannot work out how to combine a keypress with the button down callback. Is there a way to relay to the button down callback which keys were pressed at the moment the user clicked on the axis? Or should I use a key press function to monitor when the shift key is pressed and unpressed and change the value of a stored variable?
  1 comentario
Neurolab
Neurolab el 12 de Mzo. de 2024
Editada: Neurolab el 12 de Mzo. de 2024
The Matlab help pages for Button Down Callback Functions say:
"Select among different operations performed on a graphics object using modifier keys in conjunction with a left-click"
But they do not give an example or any further explanation (that I can see) for using modifier keys.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Mzo. de 2024
You need to check the figure property "SelectionType"
The ability to check the details of modifiers is for figure WindowKeyPressFcn callbacks.
  1 comentario
Neurolab
Neurolab el 12 de Mzo. de 2024
This was perfect, thank you!
In case anyone comes across this in the future, I used code like this snippet:
function button_press_callback(app, event) % in the main app
% see if a key was pressed during the mouse click
switch app.UIFigure.SelectionType
case {'extend'} % shift
case {'alt'} % ctrl
otherwise % no keypress
end
end
For my purposes this is all I need, I have not looked into other types of keypress. As far as I know the SelectionType value does not work for key combinations (i.e. ctrl + shift + k) although I have not tested this.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by