App designer button down callback with keypress

13 次查看(过去 30 天)
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 个评论
Neurolab
Neurolab 2024-3-12
编辑:Neurolab 2024-3-12
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.

请先登录,再进行评论。

采纳的回答

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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by