GUI Button with keyboard shortcut
Mostrar comentarios más antiguos
Hi,
I have a button in a GUI. The user may press it to execute the Callback. Alternatively, I would like the user to be able to press a shortcut key (for example, 'c') to press the button instead of clicking to execute the same callback.
Any ideas how to do this?
Respuesta aceptada
Más respuestas (2)
Walter Roberson
el 20 de Jul. de 2011
MyButton = uicontrol('Style','push','Callback',@whatever) set(gca, 'KeyPressFcn', @(src,event) CheckKeys(src,event,MyButton))
inside CheckKeys, if the data in the event structure shows you that the appropriate key has been pressed, then
cb = get(MyButton, 'CallBack');
cb{1}(src, [], cb{2:end})
The [] here is a fake event value, which is fine since Pushbuttons do not have a meaningful event value.
This setup presumes you used the function-handle form of setting the callback. If you used the string form of setting the callback... then Don't! that causes more trouble then it is worth.
Harry MacDowel
el 20 de Jul. de 2011
0 votos
Yes you can, Jan.
If you want to do that, you can define the KeyPressFcn by passing the input into a function you created yourself to do whatever you would like to.
I am lazy to post the whole procedure so I would give you the tutorial link on blinkdagger by Quan Quach here:-
Good luck!
1 comentario
Jan
el 20 de Jul. de 2011
Categorías
Más información sobre Desktop en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!