Quote:Original post by dank
I tested it, I measured it. I told you numerical facts about my particular keyboard, it is not my "belief" but matter of mathematics that points there indeed is the problem.
I tried the sniffer, then realized my keyboard isn't USB. I still use an ancient cherry keyboard some 15 years old, with adapter from AT to PS2. It's true what they say, they don't make them like they used to. It has outlived all of those Microsoft and Logitech high tech keyboards.
One detail on keypresses though. Data is sent serially. But detection is done instantly on the keyboard itself. It is perfectly possible to press multiple keys at same time. But as mentioned before, depending on keyboard, which keys can be pressed at same time depends on how signals are read. Whether a keyboard buffers or sends each keypress instantly and individually depends on hardware.
As for actual
wire protocol (pdf), around page 60.
Ctrl,shift and alt are sent encoded as bitmasks (4+4, left and right keys). The rest is 6 bytes for other keys. It's up to keyboard to determine how many to send per packet.
The details say the following:
- keyboard *may* buffer, meaning it is not required to send multiple keys inside same packet
- order of keycodes inside same packet doesn't matter
- Pages 68/69 then have keyboard configuration, which is where packet sizes, polling rates and similar are negotiated. Examining that might prove useful
One thing I'm not inclined to examine right now is how individual characters are encoded, but given that configuration allows code page to be set, it is likely that one byte is enough (104 keys typically). That would mean that host needs to translate raw keyboard input into something OS accepts.
As for communication, USB 1.1 had a max of 12Mbits/sec, which would in theory mean 187,000 keyboard packets per second. Not sure what actual bandwidth used by keyboards is. Seems there is also low-speed mode at 1.5Mb/sec, which is still plenty fast.
Also relevent, USB bus multiplexes different devices, where each device is given a
1ms or 0.125ms frame. So the polling resolution is limited by that and latency will get progressively worse as multiple devices share same bus.