Skip to content

BT keyboard repeats one character continuously #77

Open

Description

@Proavtor

When I tried to input a password with a length of equal to 14 symbols or more, the last (sometime the 14-th) character repeats until I turn off BT or try to input something else.
Application version: 0.5.0
Android version: 12
Host: Windows 11 24H2

Activity

  1. jralo7 commented on Mar 11, 2025

    @jralo7

    I have the same problem, sometimes the last character repeats. Also I did this:

    • Open a text editor
    • Type a long (>100 chars) password several times

    If you look close, some characters may be missing at random, specially the more chars that are typed. I think that the PC cannot receive all characters successfully, causing the repeating last character and/or missing characters.

    If so, I think a quick fix would be to add a delay between characters sent. It would be better if the delay is customizable in settings to everybody can adjust to their bluetooth devices.

    My knowledge of Java, Bluetooth and Android is limited, I looked at the code and I think the delay should be inside this, but I'm not sure. Even if I tried to modify it I wouldn't know how to compile.

    Hopefully somebody else will do it, if so I'll gladly test the app for them.

    Application version: 0.5.0
    Android version: 13
    Host: Linux Mint 21

  2. amitjaju82 commented on Sep 1, 2026

    @amitjaju82

    i fixed the apk (removed)
    It is signed with a debug license so you will have to install it fresh and cant update the developer version

  3. tejado commented on Sep 1, 2026

    @tejado
    Owner

    i fixed the apk (removed)
    It is signed with a debug license so you will have to install it fresh and cant update the developer version

    Can you provide more details about your fix? I don't feel comfortable that you provide "fixed" apks without any source to verify it.

  4. amitjaju82 commented on Sep 1, 2026

    @amitjaju82

    Auto-Type over Bluetooth leaves the last key stuck on longer passwords

    When I auto-type a password that's around 14 characters or longer, the last character often gets
    stuck down on the PC and repeats until I type something else. Short passwords are fine.

    I had a dig through the code. In HidDeviceController.sendToKeyboardHost() the key-down and
    key-up reports go out one after another with no gap at all, and HidDeviceApp.sendScancode()
    throws away whatever sendReport() returns.

    sendReport() doesn't queue anything. If the channel is busy it drops the report and returns
    false. A 14 character password is 28 reports fired back to back, so past a certain point they
    start getting dropped. If the dropped one happens to be the key-up, the PC still thinks the key
    is held and its own key repeat kicks in. That matches what I was seeing, including why it stops
    as soon as anything else gets typed.

    The clean() call is doing the right thing, it just has no way to find out it failed.

    What I changed:

    • Put a 12ms gap between reports. I picked that because the QoS in Constants.java already
      says 800 bytes/s with a 9 byte bucket, and a report is 9 bytes, so it works out to about
      11.25ms per report. The code was sending with no gap at all.
    • Actually check what sendReport() returns and retry when it's false, with a few more retries
      for key-up reports since that's the one that causes the stuck key.
    • Always finish with an all-zero report, plus a second one after a short delay just in case.

    I also had to move the typing off the main thread. It was already running there with
    SystemClock.sleep() calls in it, so adding any delay would have frozen the UI.

    Long passwords type fine now, including repeated characters and lots of capitals. No stuck keys
    so far.

    Two smaller things I noticed while in there: keyboardOutput in BluetoothForegroundService is
    never cleared, so the password stays in memory and gets typed again if the same host reconnects.
    And debug builds were logging every password character and its scancode in plain text in
    convertTextToScancode().

    Separate issue: master doesn't run on Android 14

    Probably worth its own ticket, but I couldn't test any of the above until I sorted these out.
    Looks like targetSdk went to 34 without the migration.

    1. Crashes on launch. FileTimeoutReceiver calls registerReceiver() with SCREEN_OFF plus the
      app's own FILE_TIMEOUT action, and Android 14 wants RECEIVER_EXPORTED or
      RECEIVER_NOT_EXPORTED when the filter isn't system-only. otp/ScanActivity has the same
      problem with its own action.
    2. "Bluetooth Service is not available" on pairing. BluetoothForegroundService has no
      foregroundServiceType, so startForeground() throws MissingForegroundServiceTypeException
      and the service dies every time it starts. connectedDevice is the right type for it.
    3. Same error again on a fresh install even after granting the Bluetooth permission.
      PasswdSafe.onStart() only binds the service if the permission is already granted, but it's
      first requested from BluetoothFragment, and nothing tells the activity to try again after
      you grant it. So it stays broken until Android restarts the activity on its own.

    Code

    Both fixes are on a branch in my fork, as two separate commits so they can be taken
    independently:

    The HID commit adds 22 plain JUnit tests for the report sequencing, covering 5, 13, 14, 20 and
    50 character passwords, repeated characters, case changes, symbols and shift-heavy strings, and
    checking every sequence ends with all keys released. They run on the JVM, no device needed
    (./gradlew testDebugUnitTest).

    Tested on a vivo V2562 on Android , en_US layout, typing to a laptop. I've
    only tried the one phone and the one host, so worth a second pair of eyes on the timing.

    Happy to open a PR with either or both if you want them.

  5. tejado commented on Sep 1, 2026

    @tejado
    Owner

    Great, thank you @amitjaju82. I will look into it and will fix it.

    As I'm currently in the middle of a large refactor of Authorizer, please don't open a PR for it yet.

  6. amitjaju82 commented on Sep 2, 2026

    @amitjaju82

    Hi — thanks for Authorizer. I've been using its Bluetooth auto-type as a hardware-key
    replacement for a while.

    It also fixes the Android 14 crashes (missing foregroundServiceType, and
    registerReceiver without an exported flag), moves auto-type off the main thread, and stops
    the credential lingering on the heap and in debug logs. Happy to open it as a PR if you'd
    like it.

    A heads-up. I've ported the HID transport and the layout tables into a KeePassDX fork,
    so the same feature works with .kdbx databases:
    https://github.com/amitjaju82/KeePassDX-bluetooth-keyboard

    Your files keep their original package and licence headers, and there's a
    LICENSES/BLUETOOTH-HID-PORT.md recording every change I made to them. Let me know if you'd
    like the attribution done differently.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions