Matlab adding KeyListener to existing button -
Matlab adding KeyListener to existing button -
i've written matlab programme counts different values when particular button pressed (so far numbers of "yes" , "no"). i'm trying add together key listener when press, example, n on keyboard button pressed, or same actions completed. have tried addlistener
, keyfunclistener
functions neither seems working.
here illustration of button:
no=uicontrol(h_fig,'callback',countnonerve,'position',[.65 .07 .1 .08],'string','no','style','pushbutton','units','normalized');
any suggestions? helpful i'm not familiar matlab
you seek using keypressfcn property of figure record/capture individual key presses:
function keypress_test h = figure; set(h,'keypressfcn',@keypresscb); function keypresscb(src,evnt) disp(['key pressed: ' evnt.key]); end end
the above code can pasted file , saved keypress_test.m. figure created , callback assigned keypressfcn property.
it can adapted gui. wherever have access figure handles (probably h_fig above) add together set(h_fig,'keypressfcn',@keypresscb);
, paste keypresscb code same file.
if counting number of times key pressed, have save info somewhere..probably handles structure. case? if so, can access callback
function keypresscb(src,evnt) disp(['key pressed: ' evnt.key]); % handles construction handles = guidata(src); if ~isempty(handles) % here - increment count evnt.key % save updated count guidata(src,handles); end end
try out , see happens!
matlab keylistener
Comments
Post a Comment