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

4 visualizzazioni (ultimi 30 giorni)
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?

Risposte (1)

Divyanshu
Divyanshu il 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:

Categorie

Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by