I am creating a mouse controlled virtual keyboard using pushbuttons in gui.but cant create callback code for space bar.please help. my code for space bar:
function space_Callback(hObject, eventdata, handles)
% hObject handle to space (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
OLDstring=get(handles.text1,'string');
set(handles.text1,'string',sprintf('%s %s',OLDstring,' '));
this creates space in static text but after i press another keybutton for input...the space is gone and the inputs are displayed without the space.. ..code for other input...example:for entering h:
function h_Callback(hObject, eventdata, handles)
% hObject handle to h (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
OLDstring=get(handles.text1,'string');
NEWstring=('h');
textstring=strcat(OLDstring,NEWstring);
set(handles.text1,'string',textstring);

 採用された回答

Geoff Hayes
Geoff Hayes 2016 年 9 月 28 日

1 投票

Shreyas - according to strcat, for _ character array inputs, strcat removes trailing ASCII white-space characters: space, tab, vertical tab, newline, carriage return, and form feed_. So your space is being removed by this function.
Just use the square brackets for the string concatenation. For example, your callbacks can be simplified to
function h_Callback(hObject, eventdata, handles)
str = get(handles.text1,'String');
set(handles.text1,'String',[str 'h']);
function space_Callback(hObject, eventdata, handles)
str = get(handles.text1,'String');
set(handles.text1,'String',[str ' ']);
Try the above and see what happens!

1 件のコメント

Shreyas Kagalkar
Shreyas Kagalkar 2016 年 9 月 29 日
Thank you very much for the answer

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by