Skip to content

Comments

BadUSB/BLE bugs fixes and improve writing speed#2192

Open
mokapi47 wants to merge 23 commits intoBruceDevices:devfrom
mokapi47:dev_BadUSB/BLE
Open

BadUSB/BLE bugs fixes and improve writing speed#2192
mokapi47 wants to merge 23 commits intoBruceDevices:devfrom
mokapi47:dev_BadUSB/BLE

Conversation

@mokapi47
Copy link

  • I've also reduced the delays between keystrokes (for the STRING, for example) because it was set to 50ms, which made it extremely slow to type. I've reduced this to 5ms, and it works perfectly. Typing "example" now takes ~20ms instead of 400-500ms, which is about 17 times faster. I've also changed the command delay from 75ms to 10ms.

  • Main changes:
    Default delay: 100ms → 5ms (20x faster)
    I used such a low value because most code already contains delays, so there's no need to add even more delays. For me, this is better and faster for most uses.
    Delay between characters: 50ms → 5ms (25x faster)
    For me, a value of 50 ms per character is too low; using this value, I noticed that it is quite slow to write STRINGS, so I lowered it because it seems logical to make it faster to write characters.
    Command delay: 75ms → 10ms (7.5x faster)
    Again, this is better for me because it reduces the delays between lines, so it's much faster.

  • I've obviously done extensive testing. To ensure stability and that everything works perfectly, you now have a BadUSB/BLE that works super fast, without errors, and most importantly, can be stopped at any time.

I've noticed that lately, many people are complaining about BadUSB/BLE not stopping when there are long delays or large repeats. So, I've changed some functions in the code, so that there is much more verification if the button is pressed.

Comment on lines 456 to 457
// Set appropriate delay for this STRING command - 5ms instead of defaultStringDelay
int currentDelay = (nextStringDelay >= 0) ? nextStringDelay : 5;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be left as defaultStringDelay this variable is initially set from the devices configured delay
static int defaultStringDelay = bruceConfig.badUSBBLEKeyDelay; // Default delay for all STRING commands

Then can be overridden by DEFAULT_STRING_DELAY and DEFAULTSTRINGDELAY.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, but that's precisely the whole point of my PR: to significantly reduce the delay between writing each character with STRING, because for me it's far too slow. I tried implementing what you suggested, but when I change that value in my device settings to 5ms (as I forced in the code), it simply doesn't work. So I'll leave it as I had it for now. In the meantime, feel free to suggest other ways to fix this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you send the script you are using to test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire script is on this GitHub repository : https://github.com/mokapi47/firmware/tree/dev_BadUSB/BLE

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know where the source code it.

What BadUSB script are you using to test this? So I can test using the same thing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm running STRING tests to check the writing speed, and hard tests to see if the script can be stopped. I also need to review the script stopping mechanisms I've set up, as they don't work for STRINGS. Here's the one I'm using for STRING writing speed :
DELAY 250
STRING i like potatoes, I go to Burger King every day, this sentence is just a test sentence \ ,;:?./
Don't pay attention, I just put something random.

@mokapi47
Copy link
Author

For your information, I will be implementing a new parameter to change the key string delay value in the advanced badUSB/BLE settings.

@emericklaw
Copy link
Member

There is already a setting.

image

@mokapi47
Copy link
Author

mokapi47 commented Feb 18, 2026

There is already a setting.

image

I want to set a parameter for a delay BETWEEN each character written with string; what you're showing is the delay between each line break, man...

@emericklaw
Copy link
Member

There is already a setting.

I want to set a parameter for a delay BETWEEN each character written with string; what you're showing is the delay between each line break, man...

This is not true.

In dubky_typer.cpp there is:
hid->setDelay(bruceConfig.badUSBBLEKeyDelay);

Which sets this in USBHIDKeyboard.cpp (and BLE/CH929Keyboard)

void USBHIDKeyboard::setDelay(uint32_t ms) { this->_delay_ms = ms; }

Which is then used here to write each key.

    uint8_t p = press(c); // Keydown
    delay(this->_delay_ms);
    release(c); // Keyup
    delay(this->_delay_ms);

Turn your Config Key Delay down to 5ms and you will see it being much faster. Over USB I even managed to get it lower than this but you might get some missed key strokes.

In the code I am questioning you have removed the defaultStringDelay and replaced with 5.

The setting for this is pulled from the Key Delay:

static int defaultStringDelay = bruceConfig.badUSBBLEKeyDelay; // Default delay for all STRING commands

So if you set to 5ms in the config you end up with what you have suggested but your solution also removes the ability to configure the delay between keys. Being able to configure this is very important for BadBLE which needs to operate slower.

@mokapi47 mokapi47 changed the title BadUSB/BLE fixes bugs and improve writing speed BadUSB/BLE bugs fixes and improve writing speed Feb 18, 2026
@mokapi47
Copy link
Author

I did indeed make a careless mistake; I've corrected it and implemented a parameter to manage the key delay time in milliseconds. However, I'm not finished yet; only the BadBLE function is working. I'll complete the rest properly tomorrow.

@mokapi47 mokapi47 requested a review from emericklaw February 19, 2026 00:30
@emericklaw
Copy link
Member

@mokapi47 is this ready for review yet?

@mokapi47
Copy link
Author

@mokapi47 is this ready for review yet?

Normally yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants