switching focus for keyboard input in a GUIDE created function
Mostrar comentarios más antiguos
I want to create a slider, after which you use it, a push button appears. However, instead of clicking the button, I want to enable the user to simply push a button on the keyboard with the same effect as pushing the pushbutton. The problem, I encounter, is that the pushbutton is not in the focus. There have been some answers out there, how to do it within the uicontrol environment. I want to know, how to do it within the GUI environment. Here is a sample code:
function varargout = movedslider(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @movedslider_OpeningFcn, ...
'gui_OutputFcn', @movedslider_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function movedslider_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = movedslider_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function slider1_Callback(hObject, eventdata, handles)
global v1 v2
v1=get(handles.slider1, 'value')
if v1~=v2
set(handles.pushbutton1,'visible','on')
end
function slider1_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
function pushbutton1_Callback(hObject, eventdata, handles)
global v2 v1
v2=v1;
set(handles.pushbutton1,'visible','off');
function movedslider_WindowKeyPressFcn(hObject, eventdata, handles)
keyPressed = eventdata.Key;
if strcmpi(keyPressed,'x')
uicontrol(handles.pushbutton1);
pushbutton1_Callback(handles.pushbutton1,[],handles);
end
What do I have to change, in order to have the pushbutton1 effect while pushing 'x' on the keyboard?
Thanks! Jan
1 comentario
Jan
el 8 de Feb. de 2016
Please format your question properly. See the "? Help" button to learn how to post text and code in a readable form. Thanks.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Graphics Object Properties en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!