Effacer les filtres
Effacer les filtres

Enabling space bar and arrows as hot keys

8 vues (au cours des 30 derniers jours)
Kyle Stanhouse
Kyle Stanhouse le 4 Oct 2013
Réponse apportée : Jan le 5 Oct 2013
Hello,
I'm trying to enable hot keys to execute functions in my Matlab script. In particular, I'd like to use the space bar and arrow keys. I've implemented the infrastructure to handle the event of a key press, and have successfully associated certain letters with functions, but i can't find any documentation that explains how i refer to the space bar and arrows. To be clear I just need to know the string Matlab uses to indicate the space bar and the arrow keys so that I can have them initiate functions the same way i've done with letter keys.
Thanks, Kyle

Réponse acceptée

Image Analyst
Image Analyst le 4 Oct 2013
Just check out all keys for the value they return in the keypress callback function, and note what values the arrow and space bar return. I bet the space bar returns 32 but I don't know the arrow key values off the top of my head but you can easily find out.
  2 commentaires
Image Analyst
Image Analyst le 4 Oct 2013
Kyle's answer moved here since it's a response to my Answer, not an answer in itself:
thanks for the reply!
it seems to return ' ', or an empty string for both space bar and the arrow keys. i can now get the space bar to work with ' ' but the arrow keys are still a mystery....
Image Analyst
Image Analyst le 4 Oct 2013
Kyle, you're looking at it as a character. What is it's ASCII value? Like a space = 32, '0' = 48, 'A' = 65, etc. What is the value of an arrow key?

Connectez-vous pour commenter.

Plus de réponses (1)

Jan
Jan le 5 Oct 2013
The 2nd input of the KeyPressFcn:
figure('keypressfcn', @(FigH, EventData) disp(EventData))
Now press on the desired keys and see the values of the EventData, e.g.
Character: ''
Modifier: {1x0 cell}
Key: 'rightarrow'

Catégories

En savoir plus sur Interactive Control and Callbacks 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!

Translated by