KeyboardController::process_bluetooth_HID_data reports bad button press/release data

Status
Not open for further replies.

sanels

Member
Playing with usb host and keyboard and noticed when using the shift key (any mod keys really) it does not correctly report the press/release of the correct buttons.

Just pressing and release W key shows:
KB Data: 1 0 0 26 0 0 0 0 0
Press: 119 MOD: 0
KB Data: 1 0 0 0 0 0 0 0 0
Release: 119 MOD: 0

Press and hold shift then press w, release w, release shift yields:
KB Data: 1 2 0 0 0 0 0 0 0
KB Data: 1 2 0 26 0 0 0 0 0
Press: 87 MOD: 2
KB Data: 1 2 0 0 0 0 0 0 0
Release: 87 MOD: 2
KB Data: 1 0 0 0 0 0 0 0 0

however when you press and hold w, press shift, and release shift, then release w you get:
KB Data: 1 0 0 26 0 0 0 0 0
Press: 119 MOD: 0
KB Data: 1 2 0 26 0 0 0 0 0
Release: 119 MOD: 0
KB Data: 1 0 0 26 0 0 0 0 0
Release: 87 MOD: 2
KB Data: 1 0 0 0 0 0 0 0 0
Release: 119 MOD: 0



You will notice when you press shift while holding W it erroneously reports that the w key was released when in reality the shift key was pressed. the raw data looks to be correct just the parsing within the function seems to be bugged when using mod keys if the mod key wasn't the first button pressed. Think of games where you need to run/crawl with shift/ctrl, in those scenarios you hold ie. W key and then press and release the modifiers as desired.
 
I also notice similar behavior when you press more than 1 button at a time. if you hold W, then press D, it will release w when it shouldn't.

KB Data: 1 0 0 26 0 0 0 0 0
Press: 119 MOD: 0
KB Data: 1 0 0 26 7 0 0 0 0
Release: 119 MOD: 0
Press: 100 MOD: 0

It appears the check if a key is pressed currently references report but it seems like that object does not contain good data. The rest of the code appears to indicate that the data parameter contains the data that should be checked. By adding
memcpy(report, &data[1], 8); after if (data[0] != 1) return false; it appears to correctly handle multiple buttons at the same time and also corrects the issue with mod keys releasing the button press.

I'm not sure if when you press a mod key if the press should be called of the updated character code or mod key but despite that seems like there is an error in that function referencing object that doesn't have good data. The memcpy i mentioned will load the paramter data into report so the contains function evaluates correctly but i'm not sure what wider impact of that would be. There does not appear to be any other issues as far as i can tell.
 
Status
Not open for further replies.
Back
Top