简体   繁体   中英

matlab's GUI KeyPressFcn

I am using the KeyPressFcn method for the edit box to test whether enter is pressed. I can use call_back but there is not event_data call_back function.

If I press one time on the button of Enter, than text doesn't rewrite, but if I double time on the button of Enter (speedly), than text rewrite.

What reasons this behaviour?

function WriteData(val, name, ind)
     global solver;
     switch ind
         case {14, 15}
             value = strcat('@(t)', val);      
         case 16
             value = strcat('@(x)', val);
         case {17, 18}
             value = strcat('@(x,t)', val);
     end
     eval(strcat('solver.', name, ' = ', num2str(val) ) );

function edit1_KeyPressFcn(hObject, eventdata, handles)
     val = get(hObject, 'String');
     [~, ~, var] = GetActiveData(handles.listbox1); 
     ind = get(handles.listbox1, 'Value'); 
     if (strcmp(eventdata.Key, 'return') )
         WriteData(val, var, ind );
     end

According to the documentation found in UIControl Properties ( http://www.mathworks.com/help/matlab/ref/uicontrol-properties.html;jsessionid=49b9dc47d9f964ec95a4fe2cc9f3 ),

This callback function executes when the uicontrol object has focus and the user presses a key. If you do not define a function for this property, MATLAB passes key presses to the parent figure. Repeated key presses retain the focus of the uicontrol, and the function executes with each key press. If the user presses multiple keys at approximately the same time, MATLAB detects the key press for the last key pressed.

More simply put, the Callback will be called when you press enter the first time and the KeyPressFcn will be applied on the second press.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM