I have a USB hub with 'connected' LEDs. The LED for this device dongle would turn off after about 5-10 seconds of disuse. Holding down a modifier (CTRL,ALT,SHIFT) would cause the light to flicker off briefly every 10 seconds.
Changing this setting causes the dongle LED to remain lit, which means the dongle remains powered up. I wonder if the unpowered dongle 'forgets' the keystate and does not report a release?
I would think the keyboard itself would remember states, but the 'reset' seems to cause the problem, so who knows.
The keyboard itself does not remember anything, it is just a dumb box of switches that sends any changes to the receiver. But with your observation of the hub LEDs, I now have a theory as to what happens. This is all pure conjecture, but it seems plausible
to me. It also does not contribute in the least to solving the problem, so feel free to stop reading here.
Let's assume there are three "layers" of drivers involved, USB (including power management), Keyboard and Input (not really a device driver, but the OS layer just above). There is probably a separate HID layer between USB and Keyboard, but that doesn't do anything
but dispatch events to the appropriate device class driver.
At the start of our scenario, the Ctrl key is down, but nothing else happens on the keyboard. When the USB device (the receiver) has not had any activity for ten seconds, PM makes it "inactive", a state in which it is still powered and can communicate with
the actual keyboard, but where the OS does not poll it for input events anymore.
USB signals this inactivation to Keyboard. Keyboard then clears its internal key state, to prevent any keys from repeating endlessly that were down when the device went away. *But* Keyboard only tells Input if a "normal" key is "released" by this, not modifiers
like Ctrl, so as far as Input is aware, the key is still down.
Then the actual Ctrl key is released, the keyboard radios this to the receiver, the receiver triggers an interrupt, and USB "reactivates" the device, resumes polling, picks up the "Ctrl released" event, and
forwards it up to Keyboard. Keyboard looks at it and says to itself, "This key is now up, but (checks internal state) it was up before," (because the state was reset when the device was deactivated) "so this event is clearly bogus and I'll just throw it away."
Result: Input still has the key down, and there is no way short of pressing and releasing it again on the physical keyboard to get the driver stack to acknowledge that.
If that is close to what actually happens, it leaves two questions:
- Why are modifier keys treated differently from "normal" ones? (After all, if you hold down "A", it stops repeating after ten seconds.) Probable answer: Because "A" *can* repeat, but a modifier is just turned on and off, it does not repeat while it is down.
- Is MS going to fix this (e.g. by logically "releasing" all keys, including the modifiers?
I wonder if GetKeyState()/GetAsyncKeyState() show this different behavior, where "A" goes logically "up" after ten seconds, but Ctrl does not. Something to try tomorrow.