关于HIDEmuKbd工程一直发送键值A的问题。
时间:10-02
整理:3721RD
点击:
如题,在该工程下,我把函数的代码稍作修改,
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 parameter
if ( (keys & HAL_KEY_SW_1) && (prevKey1 == 0) )
{
// pressed
hidEmuKbdSendReport( HID_KEYBOARD_A );//HID_KEYBOARD_A
prevKey1 = 1;
}
/* else if (!(keys & HAL_KEY_SW_1) && (prevKey1 == 1) )
{
// released
hidEmuKbdSendReport( KEY_NONE );
prevKey1 = 0;
}*/
//for test key2
if ( (keys & HAL_KEY_SW_2) && (prevKey2 == 0) )
{
// pressed
hidEmuKbdSendReport( KEY_RIGHT_ARROW );//HID_KEYBOARD_A
prevKey2 = 1;
}
else if ( !(keys & HAL_KEY_SW_2) && (prevKey2 == 1) )
{
// released
hidEmuKbdSendReport( KEY_NONE );
prevKey2 = 0;
}
/*
if ( (keys & HAL_KEY_SW_2) && (prevKey2 == 0) )
{
// pressed
if ( !hidBootMouseEnabled )
{
hidEmuKbdSendReport( KEY_RIGHT_ARROW );//HID_KEYBOARD_M
}
else
{
hidEmuKbdSendMouseReport( MOUSE_BUTTON_1 );
}
prevKey2 = 1;
}
else if ( !(keys & HAL_KEY_SW_2) && (prevKey2 == 1) )
{
// releasedaaaaaaaaaaaaaaaaaaaaa
if ( !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呢?求解。
Xuelin,
应该是release 按键没有发送出去。。。
