From 1cfba97c174928d5f00a3de9c0c3c0d8c645b248 Mon Sep 17 00:00:00 2001 From: jazzstack Date: Sun, 25 Oct 2026 23:47:53 +0530 Subject: [PATCH] feat(buttons): virtual key picker with F13-F24 in the Logitech button map The button map could only take a shortcut by recording a physical key press, so keys the computer's keyboard cannot produce were unreachable - exactly the F13-F24 push-to-talk use case from issue #423. - usageForCode now maps F13-F24 to the HID usages at the end of the keyboard table (0x68-0x73), and keyName prints them back, so a keyboard that does have those keys can also record them. - A new "Keys" section lists bare keys pickable from the existing searchable command list: F1-F24 (minus F5, already offered as "Reload") and the specials (Enter, Esc, Tab, Space, Backspace, Delete, Insert, Home, End, Page Up/Down, Scroll Lock, Pause, arrows). Print Screen is omitted for the same duplicate-binding reason; both keep their existing entries. Two identical bindings would highlight ambiguously in the picker, which a new uniqueness test now guards. - Section title translated in all 12 locales; key names are HID tokens and stay as code, like DPI. Fixes #423 --- .../buttons/logitech-commands.test.ts | 30 ++++++++++++++++ src/features/buttons/logitech-commands.ts | 36 +++++++++++++++++++ src/i18n/index.ts | 1 + src/i18n/locales/ar.ts | 1 + src/i18n/locales/de.ts | 1 + src/i18n/locales/es.ts | 1 + src/i18n/locales/fr.ts | 1 + src/i18n/locales/ja.ts | 1 + src/i18n/locales/ko.ts | 1 + src/i18n/locales/pt.ts | 1 + src/i18n/locales/ru.ts | 1 + src/i18n/locales/tr.ts | 1 + src/i18n/locales/vi.ts | 1 + src/i18n/locales/zh.ts | 1 + 14 files changed, 78 insertions(+) diff --git a/src/features/buttons/logitech-commands.test.ts b/src/features/buttons/logitech-commands.test.ts index 2f139e1d..8efd12aa 100644 --- a/src/features/buttons/logitech-commands.test.ts +++ b/src/features/buttons/logitech-commands.test.ts @@ -26,6 +26,36 @@ test("shortcut names read the way G HUB writes them", () => { assert.equal(keyName(0xe0), "Key 0xe0"); }); +test("F13-F24 map to the HID usages at the end of the keyboard table", () => { + assert.equal(usageForCode("F12"), 0x45); + assert.equal(usageForCode("F13"), 0x68); + assert.equal(usageForCode("F24"), 0x73); + assert.equal(keyName(0x68), "F13"); + assert.equal(keyName(0x73), "F24"); + assert.equal(shortcutText(0x68, 0), "F13"); + // A keyboard that does have the keys records them like any other. + const binding = bindingFromKeyEvent({ code: "F13", ctrlKey: false, shiftKey: false, altKey: false, metaKey: false }); + assert.deepEqual(binding, { kind: "keyboard", key: 0x68, modifiers: 0 }); +}); + +test("the virtual keyboard offers keys without needing a keypress", () => { + const keys = COMMAND_SECTIONS.find((section) => section.id === "keys"); + assert.ok(keys); + for (let n = 13; n <= 24; n += 1) { + assert.ok(keys.entries.some((entry) => entry.label === `F${n}`), `F${n} is offered`); + } + for (const label of ["Enter", "Delete", "Page Up", "Scroll Lock"]) { + assert.ok(keys.entries.some((entry) => entry.label === label), `${label} is offered`); + } + // Bare keys bind with no modifiers. + const enter = keys.entries.find((entry) => entry.label === "Enter"); + assert.deepEqual(enter?.target, { kind: "keyboard", key: 0x28, modifiers: 0 }); + // No entry anywhere duplicates another command's binding: two identical + // bindings would highlight ambiguously in the picker. + const bindings = new Set(entries.map((entry) => JSON.stringify(entry.target))); + assert.equal(bindings.size, entries.length); +}); + test("every command, written into a profile sector, reads back as that command and no other", () => { const blank = new Uint8Array(255).fill(0x00); for (const entry of entries) { diff --git a/src/features/buttons/logitech-commands.ts b/src/features/buttons/logitech-commands.ts index 3afe07a1..3e0ddba7 100644 --- a/src/features/buttons/logitech-commands.ts +++ b/src/features/buttons/logitech-commands.ts @@ -57,6 +57,13 @@ const media = (id: string, label: string, usage: number): CommandEntry => ({ target: { kind: "consumer", usage }, }); +/** A bare key with no modifiers, for the virtual keyboard list. */ +const bareKey = (label: string, usage: number): CommandEntry => ({ + id: `key:${label}`, + label, + target: { kind: "keyboard", key: usage, modifiers: 0 }, +}); + export const COMMAND_SECTIONS: readonly CommandSection[] = [ { id: "mouse", @@ -106,6 +113,29 @@ export const COMMAND_SECTIONS: readonly CommandSection[] = [ media("play-pause", "Play / pause", 205), media("next-track", "Next track", 181), media("previous-track", "Previous track", 182), ], }, + { + // Virtual keyboard (issue #423): every key the profile can store, pickable + // without a physical keypress. The record button only sees keys the + // computer's keyboard can produce, so F13-F24 and the rarer specials are + // only reachable from this list. F5 and Print Screen are omitted: their + // bindings are already offered as "Reload" and "Print screen", and two + // commands with the same binding would highlight ambiguously. Key names + // are HID tokens and stay as code. + id: "keys", + title: "Keys", + entries: [ + ...[1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24].map((n): CommandEntry => ({ + id: `key:f${n}`, + label: `F${n}`, + target: { kind: "keyboard", key: n <= 12 ? 0x39 + n : 0x68 + n - 13, modifiers: 0 }, + })), + bareKey("Enter", 0x28), bareKey("Esc", 0x29), bareKey("Tab", 0x2b), bareKey("Space", 0x2c), + bareKey("Backspace", 0x2a), bareKey("Delete", 0x4c), bareKey("Insert", 0x49), + bareKey("Home", 0x4a), bareKey("End", 0x4d), bareKey("Page Up", 0x4b), bareKey("Page Down", 0x4e), + bareKey("Scroll Lock", 0x47), bareKey("Pause", 0x48), + bareKey("←", 0x50), bareKey("→", 0x4f), bareKey("↓", 0x51), bareKey("↑", 0x52), + ], + }, { id: "system", title: "System", @@ -122,6 +152,7 @@ export function keyName(usage: number): string { if (usage >= 0x1e && usage <= 0x26) return String(usage - 0x1d); if (usage === 0x27) return "0"; if (usage >= 0x3a && usage <= 0x45) return `F${usage - 0x39}`; + if (usage >= 0x68 && usage <= 0x73) return `F${usage - 0x68 + 13}`; return KEY_NAMES[usage] ?? `Key 0x${usage.toString(16)}`; } @@ -204,6 +235,11 @@ export function usageForCode(code: string): number | null { if (digit) return digit[1] === "0" ? 0x27 : 0x1d + Number(digit[1]); const fn = /^F([1-9]|1[0-2])$/.exec(code); if (fn) return 0x39 + Number(fn[1]); + // F13-F24 sit at the end of the HID keyboard usage table. No browser key + // event produces them on a normal keyboard, which is exactly why the virtual + // picker below exists (issue #423): push-to-talk and macro users bind them. + const fnHigh = /^F(1[3-9]|2[0-4])$/.exec(code); + if (fnHigh) return 0x68 + Number(fnHigh[1]) - 13; return CODE_USAGE[code] ?? null; } diff --git a/src/i18n/index.ts b/src/i18n/index.ts index 2f4f1e7b..40d8bb65 100644 --- a/src/i18n/index.ts +++ b/src/i18n/index.ts @@ -639,6 +639,7 @@ const en = { "prof.profileStores": "Each profile stores its own DPI stages and polling rate, so those values change with the profile.", "map.remap": "Remap", "map.defaultNote": "“Default” restores a button’s factory function.", + "map.keysSection": "Keys", "pow.mode": "Mode", "pow.perfMode": "Performance mode", "diag.details": "Device details", diff --git a/src/i18n/locales/ar.ts b/src/i18n/locales/ar.ts index 81939866..1c494ed4 100644 --- a/src/i18n/locales/ar.ts +++ b/src/i18n/locales/ar.ts @@ -581,6 +581,7 @@ export const ar: Record = { "prof.profileStores": "يخزّن كل ملف مراحل DPI ومعدل الاستقصاء الخاصين به، لذا تتغير تلك القيم مع الملف.", "map.remap": "إعادة ربط", "map.defaultNote": "«افتراضي» يعيد وظيفة الزر الأصلية من المصنع.", + "map.keysSection": "المفاتيح", "pow.mode": "الوضع", "pow.perfMode": "وضع الأداء", "diag.details": "تفاصيل الجهاز", diff --git a/src/i18n/locales/de.ts b/src/i18n/locales/de.ts index 76e921ce..bce82a62 100644 --- a/src/i18n/locales/de.ts +++ b/src/i18n/locales/de.ts @@ -582,6 +582,7 @@ export const de: Record = { "prof.profileStores": "Jedes Profil speichert seine eigenen DPI-Stufen und Abfragerate, diese Werte ändern sich also mit dem Profil.", "map.remap": "Neu belegen", "map.defaultNote": "„Standard“ stellt die Werkseinstellung einer Taste wieder her.", + "map.keysSection": "Tasten", "pow.mode": "Modus", "pow.perfMode": "Leistungsmodus", "diag.details": "Gerätedetails", diff --git a/src/i18n/locales/es.ts b/src/i18n/locales/es.ts index 534b0bd0..07c0dc08 100644 --- a/src/i18n/locales/es.ts +++ b/src/i18n/locales/es.ts @@ -582,6 +582,7 @@ export const es: Record = { "prof.profileStores": "Cada perfil guarda sus propias etapas de DPI y tasa de sondeo, así que esos valores cambian con el perfil.", "map.remap": "Reasignar", "map.defaultNote": "“Predeterminado” restaura la función de fábrica de un botón.", + "map.keysSection": "Teclas", "pow.mode": "Modo", "pow.perfMode": "Modo de rendimiento", "diag.details": "Detalles del dispositivo", diff --git a/src/i18n/locales/fr.ts b/src/i18n/locales/fr.ts index e05e915d..03409bea 100644 --- a/src/i18n/locales/fr.ts +++ b/src/i18n/locales/fr.ts @@ -582,6 +582,7 @@ export const fr: Record = { "prof.profileStores": "Chaque profil enregistre ses propres étapes DPI et son taux de sondage, ces valeurs changent donc avec le profil.", "map.remap": "Réaffecter", "map.defaultNote": "« Par défaut » restaure la fonction d'usine d'un bouton.", + "map.keysSection": "Touches", "pow.mode": "Mode", "pow.perfMode": "Mode performance", "diag.details": "Détails de l'appareil", diff --git a/src/i18n/locales/ja.ts b/src/i18n/locales/ja.ts index 3b35185d..d17d2097 100644 --- a/src/i18n/locales/ja.ts +++ b/src/i18n/locales/ja.ts @@ -582,6 +582,7 @@ export const ja: Record = { "prof.profileStores": "各プロファイルは独自のDPIステージとポーリングレートを保存するため、プロファイルを切り替えるとこれらの値も変わります。", "map.remap": "再割り当て", "map.defaultNote": "「デフォルト」はボタンの出荷時の機能に戻します。", + "map.keysSection": "キー", "pow.mode": "モード", "pow.perfMode": "パフォーマンスモード", "diag.details": "デバイスの詳細", diff --git a/src/i18n/locales/ko.ts b/src/i18n/locales/ko.ts index b12eef36..18101fbb 100644 --- a/src/i18n/locales/ko.ts +++ b/src/i18n/locales/ko.ts @@ -582,6 +582,7 @@ export const ko: Record = { "prof.profileStores": "각 프로필은 자체 DPI 단계와 폴링 레이트를 저장하므로, 프로필을 전환하면 이 값들도 함께 바뀝니다.", "map.remap": "재할당", "map.defaultNote": "\"기본값\"은 버튼을 출고 시 기능으로 되돌립니다.", + "map.keysSection": "키", "pow.mode": "모드", "pow.perfMode": "성능 모드", "diag.details": "장치 세부 정보", diff --git a/src/i18n/locales/pt.ts b/src/i18n/locales/pt.ts index 42f2c54b..3c713df9 100644 --- a/src/i18n/locales/pt.ts +++ b/src/i18n/locales/pt.ts @@ -582,6 +582,7 @@ export const pt: Record = { "prof.profileStores": "Cada perfil guarda seus próprios estágios de DPI e polling rate, então esses valores mudam com o perfil.", "map.remap": "Remapear", "map.defaultNote": "“Padrão” restaura a função de fábrica do botão.", + "map.keysSection": "Teclas", "pow.mode": "Modo", "pow.perfMode": "Modo de desempenho", "diag.details": "Detalhes do dispositivo", diff --git a/src/i18n/locales/ru.ts b/src/i18n/locales/ru.ts index c0fac72e..6f0c2c3b 100644 --- a/src/i18n/locales/ru.ts +++ b/src/i18n/locales/ru.ts @@ -581,6 +581,7 @@ export const ru: Record = { "prof.profileStores": "Каждый профиль хранит свои ступени DPI и частоту опроса, поэтому эти значения меняются вместе с профилем.", "map.remap": "Переназначить", "map.defaultNote": "«По умолчанию» возвращает кнопке заводскую функцию.", + "map.keysSection": "Клавиши", "pow.mode": "Режим", "pow.perfMode": "Режим производительности", "diag.details": "Сведения об устройстве", diff --git a/src/i18n/locales/tr.ts b/src/i18n/locales/tr.ts index f00816d2..3143f3fa 100644 --- a/src/i18n/locales/tr.ts +++ b/src/i18n/locales/tr.ts @@ -570,6 +570,7 @@ export const tr: Record = { "prof.profileStores": "Her profil kendi DPI kademelerini ve yoklama hızını saklar; bu değerler profille birlikte değişir.", "map.remap": "Yeniden eşle", "map.defaultNote": "“Varsayılan”, düğmenin fabrika işlevini geri yükler.", + "map.keysSection": "Tuşlar", "pow.mode": "Mod", "pow.perfMode": "Performans modu", "diag.details": "Cihaz bilgileri", diff --git a/src/i18n/locales/vi.ts b/src/i18n/locales/vi.ts index b98f4291..bdc03ffe 100644 --- a/src/i18n/locales/vi.ts +++ b/src/i18n/locales/vi.ts @@ -532,6 +532,7 @@ export const vi: Record = { "prof.profileStores": "Mỗi profile lưu các stage DPI và polling rate riêng, vì vậy các giá trị này thay đổi theo profile.", "map.remap": "Gán lại", "map.defaultNote": "“Mặc định” khôi phục chức năng xuất xưởng của nút.", + "map.keysSection": "Phím", "pow.mode": "Chế độ", "pow.perfMode": "Chế độ hiệu năng", "diag.details": "Chi tiết thiết bị", diff --git a/src/i18n/locales/zh.ts b/src/i18n/locales/zh.ts index 85421d7c..e10d0f1a 100644 --- a/src/i18n/locales/zh.ts +++ b/src/i18n/locales/zh.ts @@ -582,6 +582,7 @@ export const zh: Record = { "prof.profileStores": "每个配置文件都存储各自的 DPI 阶段和回报率,因此这些数值会随配置文件切换而变化。", "map.remap": "重新映射", "map.defaultNote": "“默认”会恢复按键的出厂功能。", + "map.keysSection": "按键", "pow.mode": "模式", "pow.perfMode": "性能模式", "diag.details": "设备详情",