我们知道,输入法最主要的是一个DLL,里面有这样两个导出函数:7、BOOL ImeProcessKey( //处理应用程序传入的所有击键事件,监测是否是当前输入法所需的
HIMC hIMC, //应用程序句柄
UINT uVirKey, //需处理的虚键
DWORD lParam, //击键消息参数
CONST LPBYTE lpbKeyState //当前键盘状态(256字节)
)11、UINT ImeToAsciiEx( //转换编码称汉字(串)
UINT uVirKey, //虚键
UINT uScanCode, //扫描码
CONST LPBYTE lpbKeyState, //用户定义的键盘状态
LPDWORD lpdwTransBuf, //转换后的数据存放区
UINT fuState, //活动菜单标志
HIMC hIMC //当前的应用程序句柄
)在ImeProcessKey中,可以根据lParam来判断是按下键的消息还是松开键的消息。可是在ImeToAsciiEx中呢?有办法判断是按下键还是松开键的消息吗?

解决方案 »

  1.   

    lpbKeyState 这个数组的数值不可以吗?
    MSDN 说
    lpKeyState 
    [in] Pointer to a 256-byte array that contains the current keyboard state. Each element (byte) in the array contains the state of one key. If the high-order bit of a byte is set, the key is down (pressed). 
    The low bit, if set, indicates that the key is toggled on. In this function, only the toggle bit of the CAPS LOCK key is relevant. The toggle state of the NUM LOCK and SCROLL LOCK keys is ignored. 
      

  2.   

    哦,对,这个是可以。根据虚拟键值找到那个键,再查这个“按键状态数组”,查到这个键是按下的还是松开的。对对对。可是,如果第二个函数里的扫描码要是lParam就好了,因为lParam中就包含了扫描码,并且还包含了更多的信息。