How to intercept keystrokes in Matlab when starting a GUI

Do you know how to read keyboard strokes in Matlab while Matlab gui is running? (Ie, without using the "input" function, which sends an invitation to the command window and you need to press return).

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

+4
source share
3 answers

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

+3
source

First you need to declare your shape as a handle:

 fig = figure; 

then you can set the properties (in quotation marks below) to activate the functions you wrote to respond to user interactions (using the @ signs):

 set(fig,'KeyPressFcn',@keyDownListener) set(fig, 'KeyReleaseFcn', @keyUpListener); set(fig,'WindowButtonDownFcn', @mouseDownListener); set(fig,'WindowButtonUpFcn', @mouseUpListener); set(fig,'WindowButtonMotionFcn', @mouseMoveListener); 

In the above example from shooter03.m there is a space shooter MATLAB, an excellent source (from the Matlab file exchange) for many aspects of the interaction of user objects in MATLAB:

http://www.mathworks.com/matlabcentral/fileexchange/31330-daves-matlab-shooter/content/shooter03/shooter03.m

+9
source

Try:

 hf = figure; get(hf,'CurrentCharacter') 
+1
source

Source: https://habr.com/ru/post/1412972/


All Articles