App designer button down callback with keypress

13 views (last 30 days)
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 Comment
Neurolab
Neurolab on 12 Mar 2024
Edited: Neurolab on 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.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 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 Comment
Neurolab
Neurolab on 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!