So I'm making a code that displays words on the screen and the user needs to type in the word and press enter, if they get the word correct it will move to the next one and repeat the process until they get one wrong or run out of words.
My problem is that I created the GUI and am using keypressfcn in the edit text block of my GUI and I don't know how to make it register the user as pressing enter.
This is what I have so far:
%create explanation message
uicontrol('style', 'text', 'units', 'normalized', 'position', [ .33 .1 .33 .05], 'string', 'Enter your responce below:');%Position score counter
score_h = uicontrol('style', 'text', 'units', 'normalized', 'position', [.1 0 .1 .1], 'string', '0');%Score text
uicontrol('style', 'text', 'units', 'normalized', 'position', [.1 .1 .1 .05], 'string', 'Score:');%Create message area and word display area
word_h = uicontrol('style', 'text', 'units', 'normalized', 'position', [.35 .5 .3 .2],... 'string', 'Welcome to Speed Typer! Type the words as quickly as you can as they pop up in the box below and hit enter! Type ''start'' and hit enter to begin.');%Create level display and label
uicontrol('style', 'text', 'units', 'normalized', 'position', [.8 .1 .1 .05], 'string', 'Level:')level_h = uicontrol('style', 'text', 'units', 'normalized', 'position', [.8 0 .1 .1], 'string', 'N/A');%Create typing area
textbox_h = uicontrol('style', 'edit', 'units', 'normalized', 'position', ... [.33 .04 .33 .04], 'callback', {@keypressfcn, word_h, level_h});
And the function that is causing me problems:
function keypressfcn(hObject, eventdata, word_h, level_h)%determine if key pressed was enter
%compare string in text box to sting on screen and end or continue program
end
Best Answer