4

您知道如何在 Matlab gui 运行时将键盘击读读入 Matlab 吗?(即,不使用向命令窗口发送提示并需要您按回车键的“输入”功能)。

如果可能,我们希望避免使用 mex 函数。

4

3 回答 3

9

您首先必须通过句柄声明您的身材:

fig = figure;

然后您可以设置属性(在下面的引号中)以激活您为响应用户交互而编写的函数(使用 @ 符号):

set(fig,'KeyPressFcn',@keyDownListener)
set(fig, 'KeyReleaseFcn', @keyUpListener);
set(fig,'WindowButtonDownFcn', @mouseDownListener);
set(fig,'WindowButtonUpFcn', @mouseUpListener);
set(fig,'WindowButtonMotionFcn', @mouseMoveListener);

上面的例子来自shooter03.ma MATLAB space shooter,一个优秀的源码(来自matlab文件交换),用于MATLAB中用户对象交互的许多方面:

http://www.mathworks.com/matlabcentral/fileexchange/31330-daves-matlab-shooter/content/shooter03/shooter03.m

于 2012-05-22T07:23:04.460 回答
3

如果您的 GUI 基于图形,您可以使用图形属性keypressfcn定义处理键盘输入的回调函数。有关更多说明,请参见 matlab 帮助:http: //www.mathworks.de/help/techdoc/ref/figure_props.html#KeyPressFcn

于 2012-05-17T12:05:02.877 回答
2

尝试:

hf = figure;
get(hf,'CurrentCharacter')
于 2013-11-27T20:23:02.297 回答