Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/features/buttons/logitech-commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
36 changes: 36 additions & 0 deletions src/features/buttons/logitech-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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)}`;
}

Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/i18n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ export const ar: Record<I18nKey, string> = {
"prof.profileStores": "يخزّن كل ملف مراحل DPI ومعدل الاستقصاء الخاصين به، لذا تتغير تلك القيم مع الملف.",
"map.remap": "إعادة ربط",
"map.defaultNote": "«افتراضي» يعيد وظيفة الزر الأصلية من المصنع.",
"map.keysSection": "المفاتيح",
"pow.mode": "الوضع",
"pow.perfMode": "وضع الأداء",
"diag.details": "تفاصيل الجهاز",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ export const de: Record<I18nKey, string> = {
"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",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ export const es: Record<I18nKey, string> = {
"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",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ export const fr: Record<I18nKey, string> = {
"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",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ export const ja: Record<I18nKey, string> = {
"prof.profileStores": "各プロファイルは独自のDPIステージとポーリングレートを保存するため、プロファイルを切り替えるとこれらの値も変わります。",
"map.remap": "再割り当て",
"map.defaultNote": "「デフォルト」はボタンの出荷時の機能に戻します。",
"map.keysSection": "キー",
"pow.mode": "モード",
"pow.perfMode": "パフォーマンスモード",
"diag.details": "デバイスの詳細",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ export const ko: Record<I18nKey, string> = {
"prof.profileStores": "각 프로필은 자체 DPI 단계와 폴링 레이트를 저장하므로, 프로필을 전환하면 이 값들도 함께 바뀝니다.",
"map.remap": "재할당",
"map.defaultNote": "\"기본값\"은 버튼을 출고 시 기능으로 되돌립니다.",
"map.keysSection": "키",
"pow.mode": "모드",
"pow.perfMode": "성능 모드",
"diag.details": "장치 세부 정보",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/pt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ export const pt: Record<I18nKey, string> = {
"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",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ export const ru: Record<I18nKey, string> = {
"prof.profileStores": "Каждый профиль хранит свои ступени DPI и частоту опроса, поэтому эти значения меняются вместе с профилем.",
"map.remap": "Переназначить",
"map.defaultNote": "«По умолчанию» возвращает кнопке заводскую функцию.",
"map.keysSection": "Клавиши",
"pow.mode": "Режим",
"pow.perfMode": "Режим производительности",
"diag.details": "Сведения об устройстве",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ export const tr: Record<I18nKey, string> = {
"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",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/vi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ export const vi: Record<I18nKey, string> = {
"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ị",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ export const zh: Record<I18nKey, string> = {
"prof.profileStores": "每个配置文件都存储各自的 DPI 阶段和回报率,因此这些数值会随配置文件切换而变化。",
"map.remap": "重新映射",
"map.defaultNote": "“默认”会恢复按键的出厂功能。",
"map.keysSection": "按键",
"pow.mode": "模式",
"pow.perfMode": "性能模式",
"diag.details": "设备详情",
Expand Down
Loading