App designer Key-press callback

조회 수: 23 (최근 30일)
Paolo Neri
Paolo Neri 2021년 3월 10일
편집: Zel Hurewitz 2024년 7월 17일
I have a uifigure with some buttons and an axes, which show a pointcloud in realtime. I added to the uifigure a Key-press callback, so that when the keyboard is pressed, some actions are performed. This works generally fine. My problem is that I need to click a pushbutton to start the pointcloud streaming. After pushing the button, the Key-press callback does not work anymore, maybe because the focus is on the button, and not on the figure. Then, if I click with the mouse on the axis, then the Key-press callback works again: is there a way to avoid or automatize this mouse click? I found the solution exploiting java (import java.awt.Robot; import java.awt.event.*; mouse = Robot;), i.e. programmatically move the mouse pointer to the axis and click it, but it is not the proper way to solve my issue and I would like something more robust. Any suggesiont?
  댓글 수: 4
Kelsey Bettridge
Kelsey Bettridge 2021년 12월 13일
Did you ever figure this one out? I'm having the same problem. I think you are correct about the focus, but I'm having trouble coding a workaround to get the focus back on the figure. Maddening!
Paolo Neri
Paolo Neri 2021년 12월 14일
No, I could not solve the issue and I did not get any suggestion.. if you do, please post!

댓글을 달려면 로그인하십시오.

답변 (1개)

Adam Danz
Adam Danz 2021년 12월 15일
편집: Adam Danz 2021년 12월 16일
Attached is a simple demo app that contains a KeyPressFcn assigned to the uifigure and a button. The KeyPressFcn merely prints the key pressed to the command window.
At the end of the ButtonPushed callback function, the figure is activated using figure(app.UIFigure) so that it continues to respond to key strokes. This works in Matlab R2021a and later.
  댓글 수: 10
Jixiong Su
Jixiong Su 2023년 11월 3일
편집: Jixiong Su 2023년 11월 3일
Thank you for your answer!
However, In 2023b, It would be better to use WindowsKeyPress rather than KeyPress.
Zel Hurewitz
Zel Hurewitz 2024년 7월 17일
편집: Zel Hurewitz 2024년 7월 17일
In 2024a, zooming in a UIAxis seems to break the UIFigureWindowsKeyPress callback, maybe also for a similar reason about the figure being in focus.
I submitted this as its own question as well here.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by