App designer button down callback with keypress

13 visualizzazioni (ultimi 30 giorni)
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 Commento
Neurolab
Neurolab il 12 Mar 2024
Modificato: Neurolab il 12 Mar 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.

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 12 Mar 2024
You need to check the figure property "SelectionType"
The ability to check the details of modifiers is for figure WindowKeyPressFcn callbacks.
  1 Commento
Neurolab
Neurolab il 12 Mar 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by