How can I code an on-screen keyboard within a GUI to be able to update an edit text box? Similar to a keyboard on a GPS system.
Show older comments
I want to be able to code three different text boxes and when on of them is clicked, then when the on-screen keyboard is pressed it will update the edit text to form a destination? If someone could help me construct the code for the two parts of my GUI, it would be much appreciated. The code below are the two parts I would like to code first.
function start_point_Callback(hObject, eventdata, handles)
% hObject handle to start_point (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of start_point as text
% str2double(get(hObject,'String')) returns contents of start_point as a double
% --- Executes during object creation, after setting all properties.
function start_point_CreateFcn(hObject, eventdata, handles)
% hObject handle to start_point (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in A_pb.
function A_pb_Callback(hObject, eventdata, handles)
% hObject handle to A_pb (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Answers (1)
Sean de Wolski
on 17 Apr 2013
Edited: Sean de Wolski
on 17 Apr 2013
Here's how I would go about this:
function OnScreenKeyboard
%Figure and edit box
hFig = figure;
hEdit = uicontrol('Style','edit',...
'Units','normalized',...
'Position',[0.2 0.8 0.6 0.1],...
'String','');
%Letters
uicontrol('Style','pushbutton',...
'Units','normalized',...
'Position',[0.38 0.4 0.1 0.1],...
'String','A',...
'Callback',@(~,~)AddLetter('A'));
uicontrol('Style','pushbutton',...
'Units','normalized',...
'Position',[0.52 0.4 0.1 0.1],...
'String','B',...
'Callback',@(~,~)AddLetter('B'));
function AddLetter(letter)
%Called when letter pressed
%Add letter to string
set(hEdit,'string',strcat(get(hEdit,'string'),letter));
drawnow;
%NOTE: Obviously, you'll need to add features here such as
%backspace etc.
end
end
1 Comment
Anthony Gonsalves
on 15 Mar 2022
How would I make a clear all, backspace and space button for this code?
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!