【问题标题】:How to intercept key strokes in Matlab while GUI is runningGUI运行时如何在Matlab中截取击键
【发布时间】:2012-05-24 23:57:47
【问题描述】:

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

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

【问题讨论】:

    标签: matlab user-interface keyboard interception


    【解决方案1】:

    您首先必须通过句柄声明您的图形:

    fig = figure;
    

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

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

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

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        试试:

        hf = figure;
        get(hf,'CurrentCharacter')
        

        【讨论】:

          猜你喜欢
          • 2010-10-10
          • 1970-01-01
          • 2020-12-12
          • 2013-05-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多