T-vK / ESP32-BLE-Keyboard

Bluetooth LE Keyboard library for the ESP32 (Arduino IDE compatible)
2.4k stars 402 forks source link

Add small delay for writes #127

Closed samsheff closed 2 years ago

samsheff commented 2 years ago

For long strings, the write function skips a bunch of keys. This is on Windows 10, not sure if it affects other platforms or not.

Adding few millisecond delay between the key press and release solved it for me. I'm happy to make changes/corrections to my PR if needed!

T-vK commented 2 years ago

I doubt that this is a Windows 10 issue. It is much more likely to be an issue with whatever application is receiving the keyboard input, not being able to process the keystrokes fast enough. Anyway this has already been implemented. See Readme for more information. Feel free to reopen if you disagree.

samsheff commented 2 years ago

I don’t think that’s the issue. It’s the same problem regardless of application and on my MacBook Pro.

You do have the delay function implemented, but only for the NimBLE stack as far as I can see. The other functions (which my device uses for some reason) still do not implement it.

Maybe I’m missing something, but I think the issue is a bit different. Thanks for taking a look!

T-vK commented 2 years ago

I don't know about Mac OS, but on Windows many applications handle keyboard input poorly.

But okay, I understand your issue now. @sivar2311 Any ideas why the delay is only used for NimBLE?

sivar2311 commented 2 years ago

@T-vK Because we had this error with NimBLE. NimBLE was just too fast. With the normal BLE stack this was not necessary so far.

T-vK commented 2 years ago

Okay, so the easiest fix would be to just remove the #if statement and jsut keep the this->delay_ms(_delay_ms);: https://github.com/T-vK/ESP32-BLE-Keyboard/blob/82959f26cc9f82399f6794c363753c095b4b8e16/BleKeyboard.cpp#L194-L197

The disadvantage of course would be that we probably add a little too much delay for the non-NimBLE stack.

samsheff commented 2 years ago

@T-vK That delay is user adjustable as far as I can tell... So It might be ok to leave it for the user to set or just add a different default value if we're not using the nimble stack.

I'm happy to make changes to support this if you think that's the way to go.

samsheff commented 2 years ago

@T-vK I'm going through some of my open things on github, and closing the stuff that has stalled. If you'd like to add the changes or like me to modify them, please fell free to reopen.