Filter löschen
Filter löschen

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

5 Ansichten (letzte 30 Tage)
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?

Antworten (1)

Divyanshu
Divyanshu am 28 Feb. 2024
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:

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by