Skip to content

fix HID limits to support international keyboards#4361

Open
d3npa wants to merge 2 commits intoflipperdevices:devfrom
d3npa:d3npa/fix-hid-limits
Open

fix HID limits to support international keyboards#4361
d3npa wants to merge 2 commits intoflipperdevices:devfrom
d3npa:d3npa/fix-hid-limits

Conversation

@d3npa
Copy link

@d3npa d3npa commented Mar 20, 2026

I was having trouble sending pipe characters in badusb with my jp-106 key layout and it seems the reason was the limits set on the HID descriptor. The pipe character is typed with Shift+Yen, which sends a 0x89 keycode (outside the current upstream limit of dec 101 / 0x65). Backslash \ (0x87, Ro key) and underscore _ (Shift+0x87) were also affected for the same reason. The computer silently drops keycodes outside the range declared in the descriptor, so these characters never arrived.

What's new

  • LOGICAL_MAXIMUM and USAGE_MAXIMUM are raised to 255 to allow keycodes above 101 from international keyboards.

Verification

  1. Generate a layout def for basusb and drop in /badusb/assets/layouts/ja-JP.kl (script by Claude Opus 4.6)
#!/usr/bin/env python3
"""Generate Flipper Zero BadUSB keyboard layout for JIS 106-key."""

OUTPUT = "ja-JP.kl"
SHIFT = 0x02

layout = bytearray(256)  # 128 entries x 2 bytes (keycode, modifier)

def key(char, hid, mod=0):
    layout[ord(char) * 2] = hid
    layout[ord(char) * 2 + 1] = mod

# Letters
for i in range(26):
    hid = 0x04 + i
    key(chr(ord('a') + i), hid)
    key(chr(ord('A') + i), hid, SHIFT)

# Digits
for digit, hid in zip("1234567890", [0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27]):
    key(digit, hid)

# Shifted digits: ! " # $ % & ' ( )
for char, hid in zip("!\"#$%&'()", [0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26]):
    key(char, hid, SHIFT)

# Symbols
key(" ",  0x2C)
key("-",  0x2D);  key("=",  0x2D, SHIFT)
key("^",  0x2E);  key("~",  0x2E, SHIFT)
key("@",  0x2F);  key("`",  0x2F, SHIFT)
key("[",  0x30);  key("{",  0x30, SHIFT)
key("]",  0x32);  key("}",  0x32, SHIFT)
key(";",  0x33);  key("+",  0x33, SHIFT)
key(":",  0x34);  key("*",  0x34, SHIFT)
key(",",  0x36);  key("<",  0x36, SHIFT)
key(".",  0x37);  key(">",  0x37, SHIFT)
key("/",  0x38);  key("?",  0x38, SHIFT)

# International keys
key("\\", 0x87);  key("_", 0x87, SHIFT)  # Ro  (International1)
key("|",  0x89, SHIFT)  # Yen (International3)

# Control characters
key("\t", 0x2B)  # Tab
key("\n", 0x28)  # Enter (LF)
key("\r", 0x28)  # Enter (CR)

with open(OUTPUT, "wb") as f:
    f.write(layout)
print(f"wrote {OUTPUT}")
  1. Open an editor on PC (I used nano since it doesn't have auto-pairs by default)
  2. Run jis-test.txt in BadUSB (make sure to select ja-JP layout)
REM JIS 106-key layout test for Flipper Zero
REM Open a text editor on target before running

DELAY 1000
STRING abcdefghijklmnopqrstuvwxyz
ENTER
STRING ABCDEFGHIJKLMNOPQRSTUVWXYZ
ENTER
STRING 1234567890
ENTER
STRING !"#$%&'()
ENTER
STRING -=^~\|
ENTER
STRING @`[{]}
ENTER
STRING ;:+*
ENTER
STRING ,.<>/?_
ENTER
REM --- expected output ---
REM abcdefghijklmnopqrstuvwxyz
REM ABCDEFGHIJKLMNOPQRSTUVWXYZ
REM 1234567890
REM !"#$%&'()
REM -=^~\|
REM @`[{]}
REM ;:+*
REM ,.<>/?_
  1. Verify output matches:
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567890
!"#$%&'()
-=^~\|
@`[{]}
;:+*
,.<>/?_

Checklist (For Reviewer)

  • PR has description of feature/bug or link to Confluence/Jira task
  • Description contains actions to verify feature/bugfix
  • I've built this code, uploaded it to the device and verified feature/bugfix

@d3npa
Copy link
Author

d3npa commented Mar 20, 2026

I added my new keyboard ja-JP.kl as a second commit!

$ md5sum ja-JP.kl
f66387f78eb00e783ae9f119c0c859e5  ja-JP.kl

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.

1 participant