“KeyPressFcn” for “Control + C” shortcut to run a Callback

7 ビュー (過去 30 日間)
Alborz Sakhaei
Alborz Sakhaei 2017 年 11 月 16 日
編集済み: Brunno Machado de Campos 2022 年 9 月 16 日
Is it possible to setup "CTRL+C" as a shortcut to run a GUIDE Pushbutton callback? I'm using eventdata.Modifier (for CTRL) and eventdata.Key (for C) in KeyPressFcn like below:
if strcmp(eventdata.Modifier,'control') && strcmp(eventdata.Key,'c')
pushbutton_Callback(...)
end
The problem is that when I hit "Control", both "Modifier" and "Key" fields of "eventdata" set to "Control" as long as CTRL is pressed.

回答 (1 件)

Brunno Machado de Campos
Brunno Machado de Campos 2022 年 9 月 16 日
編集済み: Brunno Machado de Campos 2022 年 9 月 16 日
example:
if ~isempty(eventdata.Modifier)
if isequal(eventdata.Modifier{1},'control')
%%% uncomment next line to identify new Ctrl+ letter code
% double(eventdata.Character)
if double(eventdata.Character)==26
UndBf(hObject,eventdata,handles);
end
end
end
I just noticed that the ctrl modifier prints an invalid character (square shape) and this invalid charcter has distic value, after transformation to double, for each key. So...

カテゴリ

Help Center および File ExchangeApp Building についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by