MATLAB: How do you get the keypressfcn to register the user pushing enter, and only play the following code once they push enter

enterkeypressfcnreturnuser input

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

Mark - note the code for the textbox_h control
textbox_h = uicontrol('style', 'edit', 'units', 'normalized', 'position', ...
[.33 .04 .33 .04], 'callback', {@keypressfcn, word_h, level_h});
You are assigning your keypressfcn to the callback which, according to write callbacks using the programmatic workflow corresponds to the callback that fires when the End user triggers the component. For example: selecting a menu item, moving a slider, or pressing a push button. In your case, this callback seems to fire whenever you press Enter.
I think that if actually want to see what key the user has pressed (when this control has focus) you will want to use the KeyPressFcn instead as
textbox_h = uicontrol('style', 'edit', 'units', 'normalized', 'position', ...
[.33 .04 .33 .04], 'KeyPressFcn', {@myKeyPressFcnCallback, word_h, level_h});
Then, your myKeyPressFcnCallback would use the eventdata input to determine if the enter key has been pressed
function myKeyPressFcnCallback(hObject, eventdata, word_h, level_h)
if strcmpi(eventdata.Key,'return')
fprintf('The user has pressed the return key!\n');
end
end
Try the above and see what happens!