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

조회 수: 10 (최근 30일)
Noam Ouzana
Noam Ouzana 2021년 11월 13일
답변: Divyanshu 2024년 2월 28일
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