在 MATLAB UIMenu 中使用 Enter 作为加速器
Using Enter as Accelerator in MATLAB UIMenu
我正在 MATLAB 中构建 GUI,目前正在使用 uimenu
添加自定义菜单。我正在尝试向不同的菜单操作添加不同的加速器。
我发现传递 char(10)
(换行符)作为 uimenu
(见下文)中的加速器字符,matlab 添加 Ctrl+ Enter
作为该菜单的加速器标签。问题是当我点击 Ctrl+ Enter
时它不会 运行 回调。
知道为什么这行不通吗?我错过了什么吗? "run current section" 的 Ctrl+ Enter
是否正在取消我的通话?在那种情况下,我可以覆盖它吗?
例子
MATLAB 如何不接受的快速演示示例 Ctrl+ Enter
function test
close all
f=figure;
m=uimenu(f,'Label','test');
uimenu(m,'Label','a','callback',@hittest,'Accelerator','r');
uimenu(m,'Label','b','callback',@hittest,'Accelerator',char(10));
function hittest(h,~)
disp(h.Label)
end
end
如您所述,主应用程序似乎已注册此加速器,因此阻止您的 GUI 拦截此调用。
您可以尝试在 shortcut preferences dialog 中更改 MATLAB 的键盘快捷键。请注意,这只会影响您的 MATLAB 安装。
如果您在 -nodesktop
模式下启动 MATLAB,那么这将阻止 MATLAB IDE 启动 IDE 并且应该释放加速器供您使用。
matlab -nodesktop
既然你提到这将是一个已部署的应用程序,你总是可以使用 isdeployed
检查它是否正在 运行 作为已部署的应用程序,如果不是,那么你可以使用备用键盘快捷键,这样您就不必在没有 IDE
的情况下连续启动 MATLAB
if ~isdeployed
% Use some other keyboard shortcut for testing
set(hmenu, 'Accelerator', <some other key for testing>)
else
% Use the enter key on deployed applications
set(hmenu, 'Accelerator', char(10))
end
您也可以这样做,以便在任何时候部署您的应用程序 或 matlab 运行 与 -nodesktop
它将使用回车键:
if usejava('desktop')
% Use some other keyboard shortcut for testing
set(hmenu, 'Accelerator', <some other key for testing>)
else
% Use the enter key on deployed applications
set(hmenu, 'Accelerator', char(10))
end
我正在 MATLAB 中构建 GUI,目前正在使用 uimenu
添加自定义菜单。我正在尝试向不同的菜单操作添加不同的加速器。
我发现传递 char(10)
(换行符)作为 uimenu
(见下文)中的加速器字符,matlab 添加 Ctrl+ Enter
作为该菜单的加速器标签。问题是当我点击 Ctrl+ Enter
时它不会 运行 回调。
知道为什么这行不通吗?我错过了什么吗? "run current section" 的 Ctrl+ Enter
是否正在取消我的通话?在那种情况下,我可以覆盖它吗?
例子
MATLAB 如何不接受的快速演示示例 Ctrl+ Enter
function test
close all
f=figure;
m=uimenu(f,'Label','test');
uimenu(m,'Label','a','callback',@hittest,'Accelerator','r');
uimenu(m,'Label','b','callback',@hittest,'Accelerator',char(10));
function hittest(h,~)
disp(h.Label)
end
end
如您所述,主应用程序似乎已注册此加速器,因此阻止您的 GUI 拦截此调用。
您可以尝试在 shortcut preferences dialog 中更改 MATLAB 的键盘快捷键。请注意,这只会影响您的 MATLAB 安装。
如果您在 -nodesktop
模式下启动 MATLAB,那么这将阻止 MATLAB IDE 启动 IDE 并且应该释放加速器供您使用。
matlab -nodesktop
既然你提到这将是一个已部署的应用程序,你总是可以使用 isdeployed
检查它是否正在 运行 作为已部署的应用程序,如果不是,那么你可以使用备用键盘快捷键,这样您就不必在没有 IDE
if ~isdeployed
% Use some other keyboard shortcut for testing
set(hmenu, 'Accelerator', <some other key for testing>)
else
% Use the enter key on deployed applications
set(hmenu, 'Accelerator', char(10))
end
您也可以这样做,以便在任何时候部署您的应用程序 或 matlab 运行 与 -nodesktop
它将使用回车键:
if usejava('desktop')
% Use some other keyboard shortcut for testing
set(hmenu, 'Accelerator', <some other key for testing>)
else
% Use the enter key on deployed applications
set(hmenu, 'Accelerator', char(10))
end