Borrar filtros
Borrar filtros

App designer key press function

101 visualizaciones (últimos 30 días)
Benedict Low
Benedict Low el 4 de Nov. de 2020
Editada: Benedict Low el 9 de Nov. de 2020
Hi,
I am using App Designer, and I would like to use the key press function, such that pressing the left arrow and right arrow on the keyboard, performs the same functions as clicking the buttons "previous" and "next" respectively. My code, which doesn't work, is as follows:
function UIFigureKeyPress(app, event)
key = event.Key;
switch key
case 'rightarrow'
NextframeButtonPushed(app, event);
case 'leftarrow'
PreviousframeButtonPushed(app, event);
end
end
Was wondering if anybody knows where the problem lies. Thanks in advance for your time.
  2 comentarios
Ramya Dodla
Ramya Dodla el 4 de Nov. de 2020
Benedict Low
Benedict Low el 9 de Nov. de 2020
Editada: Benedict Low el 9 de Nov. de 2020
Thank you Ramya for responding.
I realised that the code didn't work because of the focus. The key press function only worked when the figure had focus, but not the children. Which means I had to always ensure that the focus was not on any child object, before pressing the keys.
A better solution was therefore the window key press function, because the code executes as long as the figure or any child object has focus.
function UIFigureWindowKeyPress(app, event)
key = event.Key;
switch key
case 'rightarrow'
NextframeButtonPushed(app, event);
case 'leftarrow'
PreviousframeButtonPushed(app, event);
end
end

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Desktop en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by