Change multiple push buttons with one push button?

Hello!
I am trying to make a virtual keyboard but i can not make the "shift" button for upper letters.
This is the call back function for a key :
% --- Executes on button press in Q.
function Q_Callback(hObject, eventdata, handles)
str=get(handles.edit1,'String');
set(handles.edit1,'String',[str 'q']);
This is the call back function for shift button
% --- Executes on button press in Shift.
function Shift_Callback(hObject, eventdata, handles)
% hObject handle to Shift (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Can you help me to find a solution to change the normal letter into an upper one?
Thank you!

3 件のコメント

Image Analyst
Image Analyst 2020 年 12 月 14 日
Is shift a toggle push button or a regular push button? Are you using GUIDE or App Designer? Can you attach your full m-file and .fig or .mlapp file?
gioia petrica
gioia petrica 2020 年 12 月 14 日
編集済み: gioia petrica 2020 年 12 月 14 日
I am using guide and it is a regular push button. Here is the m-file.
Rik
Rik 2020 年 12 月 14 日
For general advice and examples for how to create a GUI (and avoid using GUIDE), have look at this thread.

サインインしてコメントする。

 採用された回答

Rik
Rik 2020 年 12 月 14 日

1 投票

You can make the shift callback change a flag. That flag should be stored in the guidata struct. In the other callbacks you can use it to switch between upper and lower case.
function Shift_Callback(hObject, eventdata, handles)
handles.ShiftIsPressed=~handles.ShiftIsPressed;%invert
guidata(hObject,handles)
end
function Q_Callback(hObject, eventdata, handles)
letter='q';
add_letter(handles,letter)
end
function add_letter(handles,letter)
if handles.ShiftIsPressed
letter=upper(letter);
%if you want to un-set shift, you can set it to false here
%handles.ShiftIsPressed=false;
%guidata(gcbf,handles)
end
str=get(handles.edit1,'String');
set(handles.edit1,'String',[str letter]);
end

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

質問済み:

2020 年 12 月 14 日

回答済み:

Rik
2020 年 12 月 14 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by