How do I prevent two simultaneous key presses from tabbing away from my GUI?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Shae Morgan
le 1 Déc 2015
Modifié(e) : Shae Morgan
le 8 Déc 2015
I have a gui that allows people to listen to a sentence and then type what they think the sentence said. The problem is, if someone is typing too fast and accidentally presses two keys at the same time, instead of putting both characters in the edit box, it tabs out and goes to the command line in MatLab. How do I prevent this from happening? I'm using the following code to pause while the person types their response until "enter" gets pressed: Any ideas would be helpful
currkey=0;
% do not move on until enter key is pressed
while currkey~=13 %13 is the ascii number for the return character
pause; % wait for a keypress
currChar=get(gcf,'CurrentCharacter');
currkey = double(currChar);
if isempty(currkey)
currkey=0;
else
end
end
Any ideas?
0 commentaires
Réponse acceptée
Plus de réponses (1)
valdal
le 1 Déc 2015
Modifié(e) : valdal
le 1 Déc 2015
With KeyPressFcn and guidata :
h = uicontrol(...);
escape = false
guidata(h,escape)
set(h, 'KeyPressFcn', @key_pressed);
while ~escape
pause(0.01);
escape = guidata(h)
end
function key_pressed(h, e)
if strcmp(e.Key, 'return')
guidata(h, true)
end
end
1 commentaire
Walter Roberson
le 1 Déc 2015
Warning: using guidata() like that will destroy your handles structure if you are using GUIDE.
Voir également
Catégories
En savoir plus sur Entering Commands dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!