Posting to finish off a thread left on a cliff-edge at the old EPE forum, and give the solution. Apologies if the formatting is weird, I'm still getting used to trying to navigate around here.
In November 2017 I posted:
----8<----
I've been doing some experiments interfacing to a USB keyboard, but am getting unexpected results from continued keypresses.
Documentation says that it is the responsibility of the host to do typematic key repeats. When reading device data from a keyboard Human Interface Device, you get an 8-byte packet with up to six keypress bytes. When a key is pressed the keycode is in the packet, when the key is released, the keypress is removed from the packet.
So, that should give me:
read data: 00 00 00 00 00 00 00 00 - nothing pressed
read data: 00 00 00 00 00 00 00 00 - nothing pressed
read data: 00 00 04 00 00 00 00 00 - 'A' pressed
read data: 00 00 04 00 00 00 00 00 - 'A' still pressed
read data: 00 00 04 00 00 00 00 00 - 'A' still pressed
read data: 00 00 00 00 00 00 00 00 - 'A' released
etc.
What I am getting instead is the packet immediately after the keypress packet is a key-released packet. Also, if the key is held down after a few empty packets I get another keypress packet - the keyboard is doing typematic repeats when I, the host, should be doing it. To make things worse, I sometimes get from a press/release two pairs of press/release packets.
I get:
read data: 00 00 00 00 00 00 00 00 - nothing pressed
read data: 00 00 00 00 00 00 00 00 - nothing pressed
read data: 00 00 04 00 00 00 00 00 - 'A' pressed
read data: 00 00 00 00 00 00 00 00 - but 'A' is still pressed
read data: 00 00 00 00 00 00 00 00 - but 'A' is still pressed
a little later, with 'A' still pressed:
read data: 00 00 04 00 00 00 00 00 - 'A' pressed
read data: 00 00 00 00 00 00 00 00 - but 'A' is still pressed
read data: 00 00 00 00 00 00 00 00 - but 'A' is still pressed
etc.
And sometimes, from pressing and releasing 'A' in a normal typematic manner:
read data: 00 00 00 00 00 00 00 00 - nothing pressed
read data: 00 00 04 00 00 00 00 00 - 'A' pressed
read data: 00 00 00 00 00 00 00 00 - 'A' released
read data: 00 00 00 00 00 00 00 00 -nothing pressed
read data: 00 00 04 00 00 00 00 00 - oi! 'A' isn't pressed!
read data: 00 00 00 00 00 00 00 00 - 'A' released
read data: 00 00 00 00 00 00 00 00 -nothing pressed
Is this a familiar problem? I've been testing with a handful of UK1 layout Dell keyboards. I'm planning on getting a handful of non-Dell and non-UK keyboards from the scrappie for more testing.
----8<----
I got to the solution, but couldn't post as the old forum was locked. Here is the answer, I hope it's useful for anybody finding the orphaned question and wondering how it was resolved.
----8<----
I've more-or-less solved it, the bane of my life, inconsistant and unclear documentation.
When you ask for data from the keyboard you receive a packet length, then a packet of data. A keyboard packet is eight bytes. I was ignoring anything that wasn't an 8-byte packet as non-keyboard data.
It turns out a packet length of zero is a valid packet meaning "no change from last packet". So, doing that correctly gives me:
no key pressed:
08 00 00 00 00 00 00 00 00
00
00
00
08 00 00 00 00 00 00 00 00
00
etc.
press a key gives:
08 mm 00 kk 00 00 00 00 00
00
00
00
00
00
08 mm 00 kk 00 00 00 00 00
00
00
00
etc.
release the key gives
08 mm 00 00 00 00 00 00 00
00
00
00
etc.
I successfully implemented typematic repeat at the host end now that I was getting a consistant stream of key-on and key-off data.
----8<----
In November 2017 I posted:
----8<----
I've been doing some experiments interfacing to a USB keyboard, but am getting unexpected results from continued keypresses.
Documentation says that it is the responsibility of the host to do typematic key repeats. When reading device data from a keyboard Human Interface Device, you get an 8-byte packet with up to six keypress bytes. When a key is pressed the keycode is in the packet, when the key is released, the keypress is removed from the packet.
So, that should give me:
read data: 00 00 00 00 00 00 00 00 - nothing pressed
read data: 00 00 00 00 00 00 00 00 - nothing pressed
read data: 00 00 04 00 00 00 00 00 - 'A' pressed
read data: 00 00 04 00 00 00 00 00 - 'A' still pressed
read data: 00 00 04 00 00 00 00 00 - 'A' still pressed
read data: 00 00 00 00 00 00 00 00 - 'A' released
etc.
What I am getting instead is the packet immediately after the keypress packet is a key-released packet. Also, if the key is held down after a few empty packets I get another keypress packet - the keyboard is doing typematic repeats when I, the host, should be doing it. To make things worse, I sometimes get from a press/release two pairs of press/release packets.
I get:
read data: 00 00 00 00 00 00 00 00 - nothing pressed
read data: 00 00 00 00 00 00 00 00 - nothing pressed
read data: 00 00 04 00 00 00 00 00 - 'A' pressed
read data: 00 00 00 00 00 00 00 00 - but 'A' is still pressed
read data: 00 00 00 00 00 00 00 00 - but 'A' is still pressed
a little later, with 'A' still pressed:
read data: 00 00 04 00 00 00 00 00 - 'A' pressed
read data: 00 00 00 00 00 00 00 00 - but 'A' is still pressed
read data: 00 00 00 00 00 00 00 00 - but 'A' is still pressed
etc.
And sometimes, from pressing and releasing 'A' in a normal typematic manner:
read data: 00 00 00 00 00 00 00 00 - nothing pressed
read data: 00 00 04 00 00 00 00 00 - 'A' pressed
read data: 00 00 00 00 00 00 00 00 - 'A' released
read data: 00 00 00 00 00 00 00 00 -nothing pressed
read data: 00 00 04 00 00 00 00 00 - oi! 'A' isn't pressed!
read data: 00 00 00 00 00 00 00 00 - 'A' released
read data: 00 00 00 00 00 00 00 00 -nothing pressed
Is this a familiar problem? I've been testing with a handful of UK1 layout Dell keyboards. I'm planning on getting a handful of non-Dell and non-UK keyboards from the scrappie for more testing.
----8<----
I got to the solution, but couldn't post as the old forum was locked. Here is the answer, I hope it's useful for anybody finding the orphaned question and wondering how it was resolved.
----8<----
I've more-or-less solved it, the bane of my life, inconsistant and unclear documentation.
When you ask for data from the keyboard you receive a packet length, then a packet of data. A keyboard packet is eight bytes. I was ignoring anything that wasn't an 8-byte packet as non-keyboard data.
It turns out a packet length of zero is a valid packet meaning "no change from last packet". So, doing that correctly gives me:
no key pressed:
08 00 00 00 00 00 00 00 00
00
00
00
08 00 00 00 00 00 00 00 00
00
etc.
press a key gives:
08 mm 00 kk 00 00 00 00 00
00
00
00
00
00
08 mm 00 kk 00 00 00 00 00
00
00
00
etc.
release the key gives
08 mm 00 00 00 00 00 00 00
00
00
00
etc.
I successfully implemented typematic repeat at the host end now that I was getting a consistant stream of key-on and key-off data.
----8<----