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. Plugging them into my desktop PC gives the behaviour I expect - no double presses and repeats when I expect the input to repeat.
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. Plugging them into my desktop PC gives the behaviour I expect - no double presses and repeats when I expect the input to repeat.