我正在MATLAB中构建一个GUI,目前正在使用uimenu添加自定义菜单。我试图在不同的菜单操作中添加不同的加速器。
我发现将char(10) (换行符)作为uimenu中的加速器字符(参见下面),matlab添加了Ctrl+ Enter作为菜单的加速器标签。问题是,当我点击Ctrl+ Enter时,它将不会运行回调。
知道为什么这不管用吗?我是不是遗漏了什么?“运行当前部分”的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发布于 2016-08-01 15:09:48
正如您已经说过的,主应用程序已经注册了这个加速器,因此阻止您的GUI拦截这个调用。
您可以尝试在快捷首选项对话框中更改MATLAB的键盘快捷方式。请注意,这只会影响您安装MATLAB。
如果您在-nodesktop模式下启动MATLAB,那么这将阻止MATLAB启动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您还可以这样做,以便在部署应用程序或使用-nodesktop运行matlab时,可以使用enter键:
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))
endhttps://stackoverflow.com/questions/38702291
复制相似问题