zoukankan      html  css  js  c++  java
  • 响应键盘事件

    为了响应键盘事件,AX增加了一个系统方法task,在用户点击某些键时会调用Form的task方法,如果想对这些键实现自己的响应,可以重载task方法,在其中判断当前的_taskId为哪个值,再写自己的响应code.比如用户选中ALT时,如下代码所示:
    public int task(int _taskId)
    {
        
    int ret;
        #Task
        
        
    if( _taskId == #taskAlt)
            info(
    "I am 'Alt'");
        
    return true;
    }
    由于Task方法的调用是由平台实现的,没找到它实现的代码,并不是所有的按键都会调用task方法,只有在宏Macro->Task中定义的键被点击时才会调用,有一些组合键比如Ctrl+Shift+Enter这些在该宏中没有.
    那如果用户点击某些该宏不存在的键时想触发自己定义的处理代码该怎么办那?只能用WinAPI了.
    1.在类WINAPI中添加如下静态方法供调用:
    client static int getAsyncKeyState(int _key)
    {
     
        DLL             dll                 
    = new DLL('USER32');
        DLLFunction     getAsyncKeyState    
    = new DLLFunction(dll,'GetAsyncKeyState');

        getAsyncKeyState.returns(ExtTypes::WORD);
        getAsyncKeyState.arg(ExtTypes::DWORD);

         
    return getAsyncKeyState.call(_key);
    }
    2.添加方法调用步骤1中的方法检测用户的按键情况:
    void catchKey()
    {

        
    int ctrl,shift,enter;
        
    #define.bingo(32768)
        ;

        ctrl    
    =   WinAPI::getAsyncKeyState(0x11);
        shift   
    =   WinAPI::getAsyncKeyState(0xA0);
        enter   
    =   WinAPI::getAsyncKeyState(0x0D);

        
    if ( ctrl == #bingo &&
                shift 
    == #bingo &&
                    enter 
    == #bingo)
        
    {

            info(
    "Bingo");
        }


        
    this.setTimeOut("catchKey",10,false);

    }

    注意上面的setTimeOut方法,定时周期性调用catchKey方法检测用户的按键情况.
    3.重载run方法,调用catchKey方法.
    void run()
    {
        ;
        super();
        element.catchKey();
    }
    关于WinAPI  'GetAsyncKeyState'的用法,可以参加如下链接:
    http://msdn2.microsoft.com/en-us/library/ms646293.aspx
    OK,就这些了.
  • 相关阅读:
    mysql limit关键字
    Android入门篇2-activity调用跟数据传递
    Android入门篇1-Hello World
    flask表单提交的两种方式
    ajax异步举例
    Android平台的一些常用命令
    python设计模式1:创建型模式
    python设计模式1:导言
    Python的高级特性12:类的继承
    django复习笔记3:实战
  • 原文地址:https://www.cnblogs.com/Farseer1215/p/1052146.html
Copyright © 2011-2022 走看看