如题,在该工程下,我把函数的代码稍作修改,
static void hidEmuKbd_HandleKeys( uint8 shift, uint8 keys ) {static uint8 prevKey1 = 0;static uint8 prevKey2 = 0;//static uint8 index = 0;//可以参考Nordic的代码(void)shift; // Intentionally unreferenced parameterif ( (keys & HAL_KEY_SW_1) && (prevKey1 == 0) ){// pressedhidEmuKbdSendReport( HID_KEYBOARD_A );//HID_KEYBOARD_AprevKey1 = 1;} /* else if (!(keys & HAL_KEY_SW_1) && (prevKey1 == 1) ){// releasedhidEmuKbdSendReport( KEY_NONE );prevKey1 = 0;}*///for test key2if ( (keys & HAL_KEY_SW_2) && (prevKey2 == 0) ){// pressedhidEmuKbdSendReport( KEY_RIGHT_ARROW );//HID_KEYBOARD_AprevKey2 = 1;}else if ( !(keys & HAL_KEY_SW_2) && (prevKey2 == 1) ){// releasedhidEmuKbdSendReport( KEY_NONE );prevKey2 = 0;} /*if ( (keys & HAL_KEY_SW_2) && (prevKey2 == 0) ){// pressedif ( !hidBootMouseEnabled ){hidEmuKbdSendReport( KEY_RIGHT_ARROW );//HID_KEYBOARD_M}else{hidEmuKbdSendMouseReport( MOUSE_BUTTON_1 );}prevKey2 = 1;}else if ( !(keys & HAL_KEY_SW_2) && (prevKey2 == 1) ){// releasedaaaaaaaaaaaaaaaaaaaaaif ( !hidBootMouseEnabled ){hidEmuKbdSendReport( KEY_NONE );}else{hidEmuKbdSendMouseReport ( MOUSE_BUTTON_NONE );}prevKey2 = 0;}*/ }
编译下载后,在文本文件中,按下HAL_KEY_SW_1这个键,电脑一直打印字符,从程序来看,这条语句应该是只执行了一次:
if ( (keys & HAL_KEY_SW_1) && (prevKey1 == 0) )
{
// pressed
hidEmuKbdSendReport( HID_KEYBOARD_A );//HID_KEYBOARD_A
prevKey1 = 1;
}
从而A的键值也只发送了一次,那么为什么会一直打印字符A呢?求解。
Yan:
Xuelin,
应该是release 按键没有发送出去。。。