matlab的GUI KeyPressFcn
matlab's GUI KeyPressFcn
我正在使用编辑框的KeyPressFcn 方法来测试是否按下了enter。我可以使用 call_back 但没有 event_data call_back 功能。
如果我按一次回车键,文本不会重写,但如果我按两次回车键(快速),文本会重写。
这种行为的原因是什么?
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
根据在 UIControl 属性 (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.
更简单地说,当您第一次按下回车键时将调用回调,第二次按下时将应用 KeyPressFcn。
我正在使用编辑框的KeyPressFcn 方法来测试是否按下了enter。我可以使用 call_back 但没有 event_data call_back 功能。
如果我按一次回车键,文本不会重写,但如果我按两次回车键(快速),文本会重写。
这种行为的原因是什么?
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
根据在 UIControl 属性 (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.
更简单地说,当您第一次按下回车键时将调用回调,第二次按下时将应用 KeyPressFcn。