Writing pressed key to variable
Mostra commenti meno recenti
I want to pause the execution of my function in order to get input from the user. I would like to do this only when the key 'p' is pressed on the keyboard. I want the output to be 0 when no key is pressed and the respective key when a key is pressed. I already found a way to do it on the internet, however I always get 0 as the output even if a key is pressed. I don't seem to be able to get the variable key outside of the function scope. How can I accomplish this?
function key=pressedKey
key=0;
set(gcf,'KeyPressFcn', @detectkeystroke);
function key = detectkeystroke(~,event)
global key
key=event.Key;
end
end
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Multicore Processor Targets in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!