Issue with Key Press Events in App Designer Plot

조회 수: 3 (최근 30일)
swapna kamatam
swapna kamatam 2023년 7월 27일
답변: Shubham 2024년 10월 8일
I encountered an issue while developing the App Designer application. The plot of detection points using the plot function is not capturing key press events when the plot is paused. I've tried various approaches, but the control is not passing to the key press callbacks.
If you have any insights or suggestions, please let me know

답변 (1개)

Shubham
Shubham 2024년 10월 8일
Hi Swapna,
In MATLAB App Designer, using "pause" can block key press events because it halts code execution and UI interaction. Here's how to address this issue:
  • Replace "pause()" with a loop that checks for key presses while updating the plot.
  • Use "drawnow" to process UI events and keep the interface responsive. Here's a simple implementation:
function plotWithKeyPressHandling(app)
% Plot some data
x = 1:10;
y = rand(1, 10);
plot(app.UIAxes, x, y, 'o');
% Responsive loop for key press handling
duration = 10; % Duration in seconds
startTime = tic; % Start timer
while toc(startTime) < duration
drawnow; % Process events, including key presses
end
end
  • Ensure "WindowKeyPressFcn" is set for the " UIFigure" to capture key events.
Kindly refer to the following documentation links for more information:
Hope this helps!

카테고리

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