In Hidemukbd.c, I make some changes in function hidEmuKbd_HandleKeys as follows:
static void hidEmuKbd_HandleKeys( uint8 shift, uint8 keys ) { static uint8 prevKey1 = 0; static uint8 prevKey2 = 0; (void)shift; // Intentionally unreferenced parameter if ( (keys & HAL_KEY_SW_1) && (prevKey1 == 0) ) { // pressed //Why always send char 'A' even if I tap the HAL_KEY_SW_1 only once ? hidEmuKbdSendReport( HID_KEYBOARD_A );//HID_KEYBOARD_A prevKey1 = 1; } /* I comment it intentionally to see what will happen 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; } */ }
After the project is built and downloaded, I tap the key for 'HAL_KEY_SW_2' in a text file. My PC print char 'A' continuously. In my point of view, I think this struct :
if ( (keys & HAL_KEY_SW_1) && (prevKey1 == 0) ) { // pressed hidEmuKbdSendReport( HID_KEYBOARD_A );//HID_KEYBOARD_A prevKey1 = 1; }
execute a time whenever I tape the key. Then I cannot understand why the program will print continuous char 'A'?