adafruit / Adafruit_CircuitPython_HID

USB Human Interface Device drivers.
MIT License
364 stars 106 forks source link

Keyboard press delay #114

Closed justinworldd closed 10 months ago

justinworldd commented 1 year ago

Hello, I would like to thank you for this awesome library. To start with hardware-wise, I am using a raspberry pi zero wireless (Rev 1.1), running raspbian bullseye. I'm having an issue with keyboard_layout_us.write events happening so fast that they do not register 100 percent of the time, on the host machine. Normally the correct keycode will register, but the leading shift will be missed quite often. Instead of ^ keypess, you might get a 6 keypress. I'm using a US layout, so, it's basically only using shift key. While it doesn't occur as often on the current host machine, when connecting to a remote desktop session, or a remote desktop session in another remote desktop session, this happen very often. I can fix this issue by adding delays in the keyboard_layout_base.py _write function, after each of the press events. It would be nice to some have way to add in custom delay into the actual press command, at the keyboard.py level, which can be set on initialization. In my instance a 0.02 second delay has been enough to fix this issue, but I would expect this to be different for different hardware. I'm using this more as a password paste application, so this is more extreme then most other typing examples, as shift key is pressed or not pressed, nearly half the time for the next key. Thanks -Justin

Here is a example of sending the same string 10 times, with no modifications to this library. Correct is first line, the next 10 are showing 10 concurrent paste on a host. These are not me picking 10 bad ones out of 100 or 1000. These are just 10 concurrent keyboard_layout_us.write results.

keyboard_layout_us.write('MUnykeL!12I$HXVcRHdtaS^YkQIhU') MUnykeL!12I$HXVcRHdtaS^YkQIhU

MUnykeL112i$HXvcrhdtaS^YkQihU MUnykeL!12i$HXVcRHdtas6ykqihU MUnykel!12i4HXVcrhdtas^YkQIhU mUnykeL!12I$HxvcrHdtas^ykqIhu munykeL!12i$hXVcRHdtas^ykqihu munykeL!12I$HxVcRHdtaS6YkqIhU Munykel112i$hXVcRHdtaS^YkqIhU munykeL!12i$HXVcrhdtas6ykqihU MUnykel112I$HxvcRHdtaS6YkqIhu mUnykel112I$HXVcRhdtaS^YkQihu

Same machine, but with a (import time) time.sleep(0.20) added after each keyboard.press event on keyboard_layout_base.py _write function

keyboard_layout_us.write('MUnykeL!12I$HXVcRHdtaS^YkQIhU') MUnykeL!12I$HXVcRHdtaS^YkQIhU

MUnykeL!12I$HXVcRHdtaS^YkQIhU MUnykeL!12I$HXVcRHdtaS^YkQIhU MUnykeL!12I$HXVcRHdtaS^YkQIhU MUnykeL!12I$HXVcRHdtaS^YkQIhU MUnykeL!12I$HXVcRHdtaS^YkQIhU MUnykeL!12I$HXVcRHdtaS^YkQIhU MUnykeL!12I$HXVcRHdtaS^YkQIhU MUnykeL!12I$HXVcRHdtaS^YkQIhU MUnykeL!12I$HXVcRHdtaS^YkQIhU MUnykeL!12I$HXVcRHdtaS^YkQIhU