How to switch keyboard control from command window to GUI?
2 views (last 30 days)
Show older comments
Hi,
I am making a MATLAB GUI and would like for it to be largely keyboard-controlled, continuously recognizing if a key is being pressed and responding accordingly the wholt time the GUI is running. This is at the end of my GUI-generated script right now. op1(handles) is the call for the function where I execute other code. And I just created this generic KeyPress function (generated by right-clicking the GUI background in GUIDE). But when I run the main script, it does not seem to recognize this function to tell if a key is being pressed. It just types in the command window and does nothing in the GUI itself. It might be me putting stuff in the wrong order, or just misunderstanding what to do. Any insight would be appreciated.
1 Comment
Rik
on 29 Jan 2021
Edited: Rik
on 29 Jan 2021
I expect GUIDE has automagically set the KeyPressFcn to this function, in which case all keypresses should be captured (unless the cursos focus is in a text field).
Without the fig and m file it is often difficult to diagnose GUIDE issues, which is one of many reasons I dislike it for anything non-trivial. Please attach them to your question.
For general advice and examples for how to create a GUI (and avoid using GUIDE), have look at this thread.
Answers (0)
See Also
Categories
Find more on Desktop in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!