你知道怎么在Matlab运行时读取键盘输入吗?也就是说,不使用“input”函数(该函数会向命令窗口发送提示并需要你按回车键),希望避免使用Mex函数。
首先,你需要通过句柄声明你的图形:
fig = figure;
然后,您可以设置属性(如下所示的引号)来激活您编写的响应用户交互的功能(使用 @ 符号):
set(fig,'KeyPressFcn',@keyDownListener)
set(fig, 'KeyReleaseFcn', @keyUpListener);
set(fig,'WindowButtonDownFcn', @mouseDownListener);
set(fig,'WindowButtonUpFcn', @mouseUpListener);
set(fig,'WindowButtonMotionFcn', @mouseMoveListener);
如果您的图形用户界面是基于一个图形的,您可以使用图形属性 keypressfcn
来定义一个回调函数来处理键盘输入。有关更多描述,请参见 matlab 帮助文档: http://www.mathworks.de/help/techdoc/ref/figure_props.html#KeyPressFcn
尝试:
hf = figure;
get(hf,'CurrentCharacter')