Is there a way to assign a KeyPressFcn to a button in matlab app designer?

5 次查看(过去 30 天)
I am working on an app that has a drag and drop GUI, where I can create buttons the represents components of a system and drag them across the panel. I would like to be able to assign key commands that work while the components are being dragged, but the problem is that while dragging the focus is on the button, so the KeyPressFunction won't be activated.
I tried to maintain focus on the UIFigure with
figure(app.UIFigure)
at the end of the dragging function, but since this function is being called every time a mouse movement is detected, it slows down the app and hurts workflow.
Is there a way to assign a KeyPressFunction to the button instead, so the shifted focus won't be a problem?

回答(1 个)

Divyanshu
Divyanshu 2024-2-28
Hi Noam,
A possible workaround for your use-case can be to make use of 'WindowButtonMotionFcn' because this callback is triggered or attached to the movement of Mouse Pointer.
Since you are dragging the buttons and moving them in the UIFigure, you can try this callback.
Please refer the following documentation for further details:

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by