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});endif nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});else gui_mainfcn(gui_State, varargin{:});endfunction 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 v2v1=get(handles.slider1, 'value')if v1~=v2 set(handles.pushbutton1,'visible','on')endfunction slider1_CreateFcn(hObject, eventdata, handles)if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]);endfunction pushbutton1_Callback(hObject, eventdata, handles)global v2 v1v2=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
Best Answer