Skip to content

Keep all key sections on keyboards that use more than one - #359

Open
mglushko wants to merge 2 commits into
hrvach:mainfrom
mglushko:fix-nkro-multi-block
Open

Keep all key sections on keyboards that use more than one#359
mglushko wants to merge 2 commits into
hrvach:mainfrom
mglushko:fix-nkro-multi-block

Conversation

@mglushko

@mglushko mglushko commented Aug 5, 2026

Copy link
Copy Markdown

Hi, I had a go at issue #335.

As far as I can tell, the problem is that some keyboards list their keys in several separate sections rather than one long run. The code was only keeping the last section it came across, so everything in the earlier ones got dropped. On that Wooting the modifier keys are stored separately, which is why those kept working while nothing else did.

This change keeps all of the sections instead of only the last one.

Looking at it more closely, the Wooting actually has four sections, and one of them is only 8 bits wide. The old code worked out what counted as a key section by its size, so that short one got thrown away as well. Rather than going by size, it now looks for a section whose usage range lines up one usage per bit, which is what the extraction code already expects of anything handed to it. The modifier is the only small section that also looks like that, and it is dealt with just above, so it is left out here.

I also added a small length check so a report that comes in shorter than expected cannot read past the end of the buffer.

To test it I put together a little program that runs the real parsing code on my PC against the descriptor posted in the issue, and the keys come out right now. I also checked a plain keyboard, a normal NKRO keyboard and a composite dongle, and they parse exactly the same as before. It is here in case it is useful to anyone: https://github.com/mglushko/deskhop-hidtests

I do not own this keyboard, so I have not been able to try it on real hardware. Very happy to change anything or drop it if you would rather solve it another way.

mglushko and others added 2 commits August 5, 2026 09:22
Some keyboards list their keys in several separate sections instead of
one long run. The code was only holding on to the last section it came
across, so all the keys in the earlier sections got dropped.

On the Wooting Two HE from issue hrvach#335 this meant only the modifier keys
worked and nothing else came through.

This keeps every section instead of just the last one. It also adds a
length check so a shorter than expected report cannot read past the end
of the buffer.
The Wooting Two HE declares its key bitmap as four Usage Minimum/Maximum ranges,
not three, and the third is only 8 bits wide. The size > 32 test treated that as
noise and dropped it, so usages 0x9D to 0xA4 never made it into a block.

Recognise a section by its usage range mapping one usage per bit instead, which
is what the extraction already requires of every block it is given. The modifier
is the one small range that also maps one usage per bit, and it is handled
separately just above, so exclude it here. Requiring a non-empty range keeps out
items that never carried a Usage Minimum/Maximum and still have both ends at zero,
which would otherwise be stored as a bogus block and fail extraction for the whole
keyboard.

Parses identically to before on a boot keyboard, an NKRO keyboard, a composite
dongle and the other test descriptors; only the Wooting changes, from three
sections to four.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant