필터 지우기
필터 지우기

App designer button down callback with keypress

조회 수: 15 (최근 30일)
Neurolab
Neurolab 2024년 3월 12일
댓글: Neurolab 2024년 3월 12일
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에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by