• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 105
  • Last Modified:

How do I take action based on the user pressing 'enter' from within a Matlab text box?

I would like users to be able to enter stuff in a TextBox and hit enter, and have action taken - BUT - matlab's TextBox_Callback is called on either hitting enter OR changing focus. I can't see any way of verifying that they really pressed enter, rather than just clicking outside of the TextBox. Is there any way to either take action when they hit enter (and ONLY when they hit enter) or to find the value of the last key pressed when focus was in the TextBox?
0
sgood3
Asked:
sgood3
1 Solution
 
yuk99Commented:
I tried and failed too.

The problem is that eventdata structure, which suppose to hold data on key pressed, is not (hopefully yet) implemented for Callback function. So there is no way to check, if Callback function was run by pressing enter or changing focus. Eventdata however is implemented for TextBox_KeyPressFcn, but when user press enter, Callback called first. You may not implement it and do all assignments in KeyPressFcn:
if(strcmp(eventdata.Key,'return'))
...
end
But what to do with the string left in TextBox after changing focus? Just leave it there without validation (not good, right?) or restore previous value (no function on focus changed)?

So, my conclusion is it's not possible with current implementation.

You may do some weird staff like controlling mouse clicks in figure and checking status of all textboxes, but ask yourself, does it worth it?

0
 
sgood3Author Commented:
Hard to believe that a simple thing would be impossible, but hey, thanks at least for letting me go on to other things :)
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now