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 Center および File ExchangeDevelop 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