Search code examples
matlabuser-interfacekeyboardinterception

How to intercept key strokes in Matlab while GUI is running


Do you know how to read keyboard strokes into Matlab while a Matlab gui is running? (I.e., without using the "input" function which sends a prompt to the command window and needs you to press return).

We would like to avoid using a mex function if possible.


Solution

  • If your GUI is based on a figure, you can use the figure property keypressfcn to define a callback function that handles keyboard inputs. See the matlab help for further descriptions: http://www.mathworks.de/help/techdoc/ref/figure_props.html#KeyPressFcn