From af95eef44646fd2da0e0313959c297907049615a Mon Sep 17 00:00:00 2001 From: OpenMouse Bot Date: Fri, 4 Dec 2026 09:57:32 -0700 Subject: [PATCH 1/6] fix(razer): map buttons through any capable client and bind keys on the Viper Mini --- src/device/controller.ts | 75 ++++++++++++++++++-- src/device/incott-macros.ts | 24 ++----- src/features/devices/cards/AdvancedCards.tsx | 54 +++++++++++++- src/i18n/index.ts | 2 + src/i18n/locales/ar.ts | 2 + src/i18n/locales/de.ts | 2 + src/i18n/locales/es.ts | 2 + src/i18n/locales/fr.ts | 2 + src/i18n/locales/ja.ts | 2 + src/i18n/locales/ko.ts | 2 + src/i18n/locales/pt.ts | 2 + src/i18n/locales/ru.ts | 2 + src/i18n/locales/tr.ts | 2 + src/i18n/locales/vi.ts | 2 + src/i18n/locales/zh.ts | 2 + src/shared/hid-keys.ts | 36 ++++++++++ 16 files changed, 186 insertions(+), 27 deletions(-) create mode 100644 src/shared/hid-keys.ts diff --git a/src/device/controller.ts b/src/device/controller.ts index 71e52d19..c2f9f066 100644 --- a/src/device/controller.ts +++ b/src/device/controller.ts @@ -143,6 +143,7 @@ import type { RazerHidClient } from "@openmouse/protocol/drivers/razer/hid"; import type { RazerButtonControl, RazerButtonMapping, + RazerKeyAction, RazerToggleControl, } from "@openmouse/protocol/razer"; import type { RazerViperMiniHidClient } from "@openmouse/protocol/drivers/razer/viper-mini-hid"; @@ -2411,6 +2412,9 @@ export function applyGameProfileSnapshot(snapshot: GameProfileSnapshot): void { for (const [button, action] of Object.entries(s.buttonMappings ?? {})) applyDeviceButtonMapping(button, action); for (const [control, mapping] of Object.entries(s.razerButtonMappings ?? {})) { + // A key assignment reads back as a label like "Ctrl+F13", which cannot be + // replayed: the write needs mods and usage, and a label does not carry them. + if (!(C().RAZER_BUTTON_MAPPINGS as readonly string[]).includes(mapping)) continue; applyRazerButtonMapping(control as RazerButtonControl, mapping as RazerButtonMapping); } @@ -6975,12 +6979,44 @@ export function applyLowPowerThreshold(percent: number): void { } /** - * Only the base `RazerHidClient` carries the class `0x02` button commands — - * the Viper Mini, Viper and Cobra siblings claim their own single product ids - * and have never been checked against it. + * Any Razer client that carries the class `0x02` button commands. + * + * Checked by capability, not by class: the base `RazerHidClient` was the only + * driver with them for a long time, but the Viper Mini's own client now + * implements `setButtonMapping` too. A class check silently dropped it, so the + * Buttons card rendered from `razerButtonMappings` while every dropdown in it + * staged nothing — the row looked editable and did nothing. */ -function razerButtonClient(): RazerHidClient | null { - return activeAs(CM()?.RazerHidClient); +type ButtonMappingClient = Pick; +type ToggleControlClient = Pick; + +function razerClientWith(method: string): Record | null { + const client = razerClient(); + if (!client) return null; + const candidate = client as unknown as Record; + return typeof candidate[method] === "function" ? candidate : null; +} + +function razerButtonClient(): ButtonMappingClient | null { + return razerClientWith("setButtonMapping") as ButtonMappingClient | null; +} + +function razerToggleClient(): ToggleControlClient | null { + return razerClientWith("setToggleControl") as ToggleControlClient | null; +} + +/** The Viper Mini's client carries the keyboard-mapping write; others do not. */ +type KeyboardMappingClient = { + setKeyboardMapping(control: RazerButtonControl, key: RazerKeyAction): Promise; +}; + +function razerKeyClient(): KeyboardMappingClient | null { + return razerClientWith("setKeyboardMapping") as KeyboardMappingClient | null; +} + +/** Whether the connected Razer client can write a keyboard key to a button. */ +export function supportsRazerKeyMapping(): boolean { + return razerKeyClient() !== null; } export function applyRazerButtonMapping(control: RazerButtonControl, mapping: RazerButtonMapping): void { @@ -7001,8 +7037,33 @@ export function applyRazerButtonMapping(control: RazerButtonControl, mapping: Ra }); } +/** + * Assigns a keyboard key to a Razer control. Only models whose firmware has + * been checked for the encoding get here: the Viper Mini stores + * `02 02 ` and physically sends it, confirmed with `wev`. + */ +export function applyRazerKeyMapping(control: RazerButtonControl, key: RazerKeyAction): void { + if (!razerKeyClient()) return; + const name = C().RAZER_BUTTON_CONTROL_LABEL[control]; + const label = C().razerKeyLabel(key); + stageChange({ + key: `razer-button-${control}`, + label: `${name} → ${label}`, + command: `Change ${name} mapping`, + progress: `Changing ${name} mapping…`, + preview: (status) => { + if (status.razerButtonMappings) status.razerButtonMappings[control] = label; + }, + apply: async () => { + const client = razerKeyClient(); + if (!client) throw new Error(st("ctl.gone")); + await client.setKeyboardMapping(control, key); + }, + }); +} + export function applyRazerToggleControl(control: RazerToggleControl, label: string): void { - if (!razerButtonClient()) return; + if (!razerToggleClient()) return; const name = C().RAZER_TOGGLE_CONTROL_INFO[control].label; stageChange({ key: `razer-toggle-${control}`, @@ -7013,7 +7074,7 @@ export function applyRazerToggleControl(control: RazerToggleControl, label: stri if (status.razerButtonMappings) status.razerButtonMappings[control] = label; }, apply: async () => { - const client = razerButtonClient(); + const client = razerToggleClient(); if (!client) throw new Error(st("ctl.gone")); await client.setToggleControl(control, label); }, diff --git a/src/device/incott-macros.ts b/src/device/incott-macros.ts index 00489316..07f90112 100644 --- a/src/device/incott-macros.ts +++ b/src/device/incott-macros.ts @@ -8,6 +8,7 @@ import { type IncottMacroLoop, type IncottMacroStep, } from "@openmouse/protocol/incott"; +import { HID_KEY_USAGES, hidKeyUsage } from "../shared/hid-keys.ts"; /** * Local store for Incott macros: a library of named macros, plus which button @@ -325,20 +326,9 @@ export const INCOTT_MACRO_DEFAULT_ACTION: Readonly([ - ...Array.from({ length: 26 }, (_, i) => [`Key${String.fromCharCode(65 + i)}`, 0x04 + i] as const), - ...Array.from({ length: 9 }, (_, i) => [`Digit${i + 1}`, 0x1e + i] as const), - ["Digit0", 0x27], - ...Array.from({ length: 12 }, (_, i) => [`F${i + 1}`, 0x3a + i] as const), - ["Enter", 0x28], ["Escape", 0x29], ["Backspace", 0x2a], ["Tab", 0x2b], ["Space", 0x2c], - ["Insert", 0x49], ["Delete", 0x4c], ["Home", 0x4a], ["End", 0x4d], - ["PageUp", 0x4b], ["PageDown", 0x4e], - ["ArrowUp", 0x52], ["ArrowDown", 0x51], ["ArrowLeft", 0x50], ["ArrowRight", 0x4f], - ["CapsLock", 0x39], ["NumLock", 0x53], ["ScrollLock", 0x47], - ["PrintScreen", 0x46], ["Pause", 0x48], ["ContextMenu", 0x65], - ["ControlLeft", 0xe0], ["ShiftLeft", 0xe1], ["AltLeft", 0xe2], ["MetaLeft", 0xe3], - ["ControlRight", 0xe4], ["ShiftRight", 0xe5], ["AltRight", 0xe6], ["MetaRight", 0xe7], -]); +export function incottMacroKeyForCode(code: string): number | null { + return hidKeyUsage(code); +} /** `MouseEvent.button` -> macro key. Only the three buttons the table has. */ const MOUSE_BY_BUTTON = new Map([ @@ -347,10 +337,6 @@ const MOUSE_BY_BUTTON = new Map([ [2, INCOTT_MACRO_MOUSE_KEYS.right], ]); -export function incottMacroKeyForCode(code: string): number | null { - return KEY_BY_CODE.get(code) ?? null; -} - export function incottMacroKeyForMouseButton(button: number): number | null { return MOUSE_BY_BUTTON.get(button) ?? null; } @@ -362,5 +348,5 @@ export function incottMacroKeyName(key: number): string { /** Every key a step can be set to: mouse buttons first, then the keyboard. */ export const INCOTT_MACRO_KEY_CHOICES: Readonly<{ mouse: readonly number[]; keyboard: readonly number[] }> = { mouse: [INCOTT_MACRO_MOUSE_KEYS.left, INCOTT_MACRO_MOUSE_KEYS.right, INCOTT_MACRO_MOUSE_KEYS.middle], - keyboard: [...KEY_BY_CODE.values()], + keyboard: [...HID_KEY_USAGES], }; diff --git a/src/features/devices/cards/AdvancedCards.tsx b/src/features/devices/cards/AdvancedCards.tsx index 8c9bcd53..185d46a9 100644 --- a/src/features/devices/cards/AdvancedCards.tsx +++ b/src/features/devices/cards/AdvancedCards.tsx @@ -13,6 +13,7 @@ import { RAZER_BUTTON_CONTROLS, RAZER_BUTTON_CONTROL_LABEL, RAZER_BUTTON_MAPPINGS, + RAZER_KEY_MODIFIERS, RAZER_LOCKED_BUTTON_CONTROL, RAZER_TOGGLE_CONTROLS, RAZER_TOGGLE_CONTROL_INFO, @@ -20,6 +21,7 @@ import { type RazerButtonMapping, type RazerToggleControl, } from "@openmouse/protocol/razer"; +import { hidKeyUsage, isModifierCode } from "../../../shared/hid-keys"; import { teevolutionSensorModeUi } from "@openmouse/protocol/teevolution"; import type { KsnakeMacroProfile, KsnakeMacroStep } from "@openmouse/protocol/ksnake"; import type { WallhackMacroStep } from "@openmouse/protocol/wallhack"; @@ -1587,9 +1589,42 @@ export function EggCpiCard({ snapshot }: { snapshot: ControlSnapshot }): ReactNo * Laid out with `button-remap-list`/`button-remap-row` to match * `MxMasterButtonsCard`, the other remap card in this same tab. */ + +/** OptionMenu sentinel: picking this starts a key capture instead of a mapping. */ +const RAZER_KEY_OPTION = "__razer_key__"; + export function RazerButtonCard({ snapshot }: { snapshot: ControlSnapshot }): ReactNode { const locale = snapshot.preferences.locale; const mappings = snapshot.status?.razerButtonMappings; + // Only the models whose firmware was checked for the key encoding offer it — + // the Viper Mini stores `02 02 ` where the older clients have + // no keyboard write at all. + const keyCapable = control.supportsRazerKeyMapping(); + const [capturing, setCapturing] = useState(null); + useEffect(() => { + if (!capturing) return undefined; + const onKeyDown = (event: KeyboardEvent): void => { + // A bare modifier is the start of a chord, not the key itself. + if (isModifierCode(event.code)) return; + event.preventDefault(); + event.stopPropagation(); + if (event.code === "Escape") { + setCapturing(null); + return; + } + if (event.repeat) return; + const usage = hidKeyUsage(event.code); + if (usage === null) return; + const mods = (event.ctrlKey ? RAZER_KEY_MODIFIERS.ctrl ?? 0 : 0) + | (event.shiftKey ? RAZER_KEY_MODIFIERS.shift ?? 0 : 0) + | (event.altKey ? RAZER_KEY_MODIFIERS.alt ?? 0 : 0) + | (event.metaKey ? RAZER_KEY_MODIFIERS.meta ?? 0 : 0); + control.applyRazerKeyMapping(capturing, { mods, usage }); + setCapturing(null); + }; + window.addEventListener("keydown", onKeyDown, true); + return () => window.removeEventListener("keydown", onKeyDown, true); + }, [capturing]); if (!mappings) return null; const busy = snapshot.settingInProgress; const rows: Array<{ key: string; name: string; current: string; options: readonly string[]; locked: boolean }> = []; @@ -1636,7 +1671,14 @@ export function RazerButtonCard({ snapshot }: { snapshot: ControlSnapshot }): Re {rows.map((row) => { const staged = snapshot.pending.keys.includes(row.key); const known = row.options.includes(row.current); + const rowControl = row.key.startsWith("razer-button-") + ? row.key.slice("razer-button-".length) as RazerButtonControl + : null; const applyRazerRow = (value: string): void => { + if (value === RAZER_KEY_OPTION && rowControl) { + setCapturing(rowControl); + return; + } if (row.key.startsWith("razer-button-")) { control.applyRazerButtonMapping( row.key.slice("razer-button-".length) as RazerButtonControl, @@ -1656,13 +1698,23 @@ export function RazerButtonCard({ snapshot }: { snapshot: ControlSnapshot }): Re data-pending-key={row.key} > {displayText(locale, row.name)} - {row.locked ? {displayText(locale, row.current)} : ( + {row.locked ? {displayText(locale, row.current)} : capturing === rowControl ? ( + + {t(locale, "adv.pressKey")} + + + ) : ( ({ value: option, label: option })), + ...(keyCapable && rowControl + ? [{ value: RAZER_KEY_OPTION, label: t(locale, "adv.keyboardShortcut") }] + : []), ]} value={row.current} disabled={busy} diff --git a/src/i18n/index.ts b/src/i18n/index.ts index 9a70e370..3ab9483d 100644 --- a/src/i18n/index.ts +++ b/src/i18n/index.ts @@ -743,6 +743,8 @@ const en = { "adv.applyStage": "Apply stage", "adv.mapping": "Mapping", "adv.razerLocked": "{name} is fixed on the Standard layer and cannot be reassigned or disabled.", + "adv.keyboardShortcut": "Keyboard shortcut…", + "adv.pressKey": "Press a key, or Esc to cancel", "adv.multiclick": "Multiclick filter", "adv.eggButtonTitle": "Multiclick and mapping", "adv.eggSensor": "Sensor controls", diff --git a/src/i18n/locales/ar.ts b/src/i18n/locales/ar.ts index cdfe7869..932e1a96 100644 --- a/src/i18n/locales/ar.ts +++ b/src/i18n/locales/ar.ts @@ -685,6 +685,8 @@ export const ar: Record = { "adv.applyStage": "تطبيق المرحلة", "adv.mapping": "الربط", "adv.razerLocked": "{name} ثابت على الطبقة القياسية ولا يمكن إعادة تعيينه أو تعطيله.", + "adv.keyboardShortcut": "اختصار لوحة المفاتيح…", + "adv.pressKey": "اضغط مفتاحًا، أو Esc للإلغاء", "adv.multiclick": "مرشح النقر المتعدد", "adv.eggButtonTitle": "النقر المتعدد والربط", "adv.eggSensor": "عناصر التحكم بالمستشعر", diff --git a/src/i18n/locales/de.ts b/src/i18n/locales/de.ts index f2075a7d..ac6d0eb5 100644 --- a/src/i18n/locales/de.ts +++ b/src/i18n/locales/de.ts @@ -686,6 +686,8 @@ export const de: Record = { "adv.applyStage": "Stufe anwenden", "adv.mapping": "Belegung", "adv.razerLocked": "{name} ist auf der Standard-Ebene fixiert und kann nicht neu zugewiesen oder deaktiviert werden.", + "adv.keyboardShortcut": "Tastenkürzel…", + "adv.pressKey": "Taste drücken, Esc zum Abbrechen", "adv.multiclick": "Mehrfachklick-Filter", "adv.eggButtonTitle": "Mehrfachklick und Belegung", "adv.eggSensor": "Sensor-Steuerung", diff --git a/src/i18n/locales/es.ts b/src/i18n/locales/es.ts index 34a7e0a3..8defdbc9 100644 --- a/src/i18n/locales/es.ts +++ b/src/i18n/locales/es.ts @@ -686,6 +686,8 @@ export const es: Record = { "adv.applyStage": "Aplicar etapa", "adv.mapping": "Mapeo", "adv.razerLocked": "{name} está fijado en la capa Standard y no se puede reasignar ni desactivar.", + "adv.keyboardShortcut": "Atajo de teclado…", + "adv.pressKey": "Pulsa una tecla, Esc para cancelar", "adv.multiclick": "Filtro de multiclic", "adv.eggButtonTitle": "Multiclic y mapeo", "adv.eggSensor": "Controles del sensor", diff --git a/src/i18n/locales/fr.ts b/src/i18n/locales/fr.ts index e801b8a9..0aa54390 100644 --- a/src/i18n/locales/fr.ts +++ b/src/i18n/locales/fr.ts @@ -686,6 +686,8 @@ export const fr: Record = { "adv.applyStage": "Appliquer l'étape", "adv.mapping": "Mappage", "adv.razerLocked": "{name} est fixé sur la couche Standard et ne peut pas être réaffecté ou désactivé.", + "adv.keyboardShortcut": "Raccourci clavier…", + "adv.pressKey": "Appuyez sur une touche, Échap pour annuler", "adv.multiclick": "Filtre multiclic", "adv.eggButtonTitle": "Multiclic et mappage", "adv.eggSensor": "Contrôles du capteur", diff --git a/src/i18n/locales/ja.ts b/src/i18n/locales/ja.ts index 782ad07a..099e223a 100644 --- a/src/i18n/locales/ja.ts +++ b/src/i18n/locales/ja.ts @@ -686,6 +686,8 @@ export const ja: Record = { "adv.applyStage": "ステージを適用", "adv.mapping": "マッピング", "adv.razerLocked": "{name}はStandardレイヤーに固定されており、再割り当てや無効化はできません。", + "adv.keyboardShortcut": "キーボードショートカット…", + "adv.pressKey": "キーを押してください(Esc でキャンセル)", "adv.multiclick": "マルチクリックフィルター", "adv.eggButtonTitle": "マルチクリックとマッピング", "adv.eggSensor": "センサーコントロール", diff --git a/src/i18n/locales/ko.ts b/src/i18n/locales/ko.ts index 3006db45..7c287b7e 100644 --- a/src/i18n/locales/ko.ts +++ b/src/i18n/locales/ko.ts @@ -686,6 +686,8 @@ export const ko: Record = { "adv.applyStage": "단계 적용", "adv.mapping": "매핑", "adv.razerLocked": "{name}은(는) Standard 레이어에 고정되어 재할당하거나 비활성화할 수 없습니다.", + "adv.keyboardShortcut": "키보드 단축키…", + "adv.pressKey": "키를 누르세요 (Esc로 취소)", "adv.multiclick": "다중 클릭 필터", "adv.eggButtonTitle": "다중 클릭 및 매핑", "adv.eggSensor": "센서 컨트롤", diff --git a/src/i18n/locales/pt.ts b/src/i18n/locales/pt.ts index 62f96c86..538d6e65 100644 --- a/src/i18n/locales/pt.ts +++ b/src/i18n/locales/pt.ts @@ -686,6 +686,8 @@ export const pt: Record = { "adv.applyStage": "Aplicar estágio", "adv.mapping": "Mapeamento", "adv.razerLocked": "{name} é fixo na camada Standard e não pode ser reatribuído nem desativado.", + "adv.keyboardShortcut": "Atalho de teclado…", + "adv.pressKey": "Pressione uma tecla, Esc para cancelar", "adv.multiclick": "Filtro multiclique", "adv.eggButtonTitle": "Multiclique e mapeamento", "adv.eggSensor": "Controles do sensor", diff --git a/src/i18n/locales/ru.ts b/src/i18n/locales/ru.ts index fd59167e..ecda7d53 100644 --- a/src/i18n/locales/ru.ts +++ b/src/i18n/locales/ru.ts @@ -685,6 +685,8 @@ export const ru: Record = { "adv.applyStage": "Применить ступень", "adv.mapping": "Назначение", "adv.razerLocked": "{name} закреплена на слое Standard и не переназначается и не отключается.", + "adv.keyboardShortcut": "Сочетание клавиш…", + "adv.pressKey": "Нажмите клавишу, Esc для отмены", "adv.multiclick": "Фильтр мультикликов", "adv.eggButtonTitle": "Мультиклик и назначение", "adv.eggSensor": "Управление сенсором", diff --git a/src/i18n/locales/tr.ts b/src/i18n/locales/tr.ts index ed437bdb..56ebe0c3 100644 --- a/src/i18n/locales/tr.ts +++ b/src/i18n/locales/tr.ts @@ -674,6 +674,8 @@ export const tr: Record = { "adv.applyStage": "Kademeyi uygula", "adv.mapping": "Eşleme", "adv.razerLocked": "{name}, Standart katmanda sabittir; yeniden atanamaz veya devre dışı bırakılamaz.", + "adv.keyboardShortcut": "Klavye kısayolu…", + "adv.pressKey": "Bir tuşa basın, iptal için Esc", "adv.multiclick": "Çoklu tıklama filtresi", "adv.eggButtonTitle": "Çoklu tıklama ve eşleme", "adv.eggSensor": "Sensör denetimleri", diff --git a/src/i18n/locales/vi.ts b/src/i18n/locales/vi.ts index a03e1ec3..fe032505 100644 --- a/src/i18n/locales/vi.ts +++ b/src/i18n/locales/vi.ts @@ -636,6 +636,8 @@ export const vi: Record = { "adv.applyStage": "Áp dụng stage", "adv.mapping": "Gán nút", "adv.razerLocked": "{name} được cố định trên layer Standard và không thể gán lại hoặc tắt.", + "adv.keyboardShortcut": "Phím tắt…", + "adv.pressKey": "Nhấn một phím, Esc để huỷ", "adv.multiclick": "Bộ lọc multiclick", "adv.eggButtonTitle": "Multiclick và gán nút", "adv.eggSensor": "Điều khiển cảm biến", diff --git a/src/i18n/locales/zh.ts b/src/i18n/locales/zh.ts index be9c3860..a74c81c1 100644 --- a/src/i18n/locales/zh.ts +++ b/src/i18n/locales/zh.ts @@ -686,6 +686,8 @@ export const zh: Record = { "adv.applyStage": "应用阶段", "adv.mapping": "映射", "adv.razerLocked": "{name} 固定在标准层,无法重新分配或禁用。", + "adv.keyboardShortcut": "键盘快捷键…", + "adv.pressKey": "按下按键,按 Esc 取消", "adv.multiclick": "多击滤波器", "adv.eggButtonTitle": "多击与映射", "adv.eggSensor": "传感器控制", diff --git a/src/shared/hid-keys.ts b/src/shared/hid-keys.ts new file mode 100644 index 00000000..f12cf873 --- /dev/null +++ b/src/shared/hid-keys.ts @@ -0,0 +1,36 @@ +/** + * Browser `KeyboardEvent.code` -> HID keyboard usage. + * + * One table for every card that lets a user press a key to bind it. Keys outside + * it are left out on purpose: a code with no usage would be written to a device + * as a key it cannot name back. + */ +const KEY_BY_CODE = new Map([ + ...Array.from({ length: 26 }, (_, i) => [`Key${String.fromCharCode(65 + i)}`, 0x04 + i] as const), + ...Array.from({ length: 9 }, (_, i) => [`Digit${i + 1}`, 0x1e + i] as const), + ["Digit0", 0x27], + ...Array.from({ length: 12 }, (_, i) => [`F${i + 1}`, 0x3a + i] as const), + ["Enter", 0x28], ["Escape", 0x29], ["Backspace", 0x2a], ["Tab", 0x2b], ["Space", 0x2c], + ["Insert", 0x49], ["Delete", 0x4c], ["Home", 0x4a], ["End", 0x4d], + ["PageUp", 0x4b], ["PageDown", 0x4e], + ["ArrowUp", 0x52], ["ArrowDown", 0x51], ["ArrowLeft", 0x50], ["ArrowRight", 0x4f], + ["CapsLock", 0x39], ["NumLock", 0x53], ["ScrollLock", 0x47], + ["PrintScreen", 0x46], ["Pause", 0x48], ["ContextMenu", 0x65], + ["ControlLeft", 0xe0], ["ShiftLeft", 0xe1], ["AltLeft", 0xe2], ["MetaLeft", 0xe3], + ["ControlRight", 0xe4], ["ShiftRight", 0xe5], ["AltRight", 0xe6], ["MetaRight", 0xe7], +]); + +export function hidKeyUsage(code: string): number | null { + return KEY_BY_CODE.get(code) ?? null; +} + +/** Every usage the table can produce, for menus that list bindable keys. */ +export const HID_KEY_USAGES: readonly number[] = [...new Set(KEY_BY_CODE.values())]; + +/** True for a bare modifier press, which a chord recorder waits past. */ +export function isModifierCode(code: string): boolean { + return code === "ShiftLeft" || code === "ShiftRight" + || code === "ControlLeft" || code === "ControlRight" + || code === "AltLeft" || code === "AltRight" + || code === "MetaLeft" || code === "MetaRight"; +} From f8b98afe7036f6ddf7923d1cda8016f003e6ee03 Mon Sep 17 00:00:00 2001 From: OpenMouse Bot Date: Fri, 4 Dec 2026 10:27:39 -0700 Subject: [PATCH 2/6] feat(razer): show the bottom button row and offer Hypershift where it is verified --- src/features/devices/cards/AdvancedCards.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/features/devices/cards/AdvancedCards.tsx b/src/features/devices/cards/AdvancedCards.tsx index 185d46a9..96ce84c6 100644 --- a/src/features/devices/cards/AdvancedCards.tsx +++ b/src/features/devices/cards/AdvancedCards.tsx @@ -1628,14 +1628,19 @@ export function RazerButtonCard({ snapshot }: { snapshot: ControlSnapshot }): Re if (!mappings) return null; const busy = snapshot.settingInProgress; const rows: Array<{ key: string; name: string; current: string; options: readonly string[]; locked: boolean }> = []; - for (const con of RAZER_BUTTON_CONTROLS) { + // The bottom button is a fifth control on models whose firmware stores a + // plain action there rather than the sensitivity toggle; a model that does + // not answer for it simply contributes no row. + const order: RazerButtonControl[] = [...RAZER_BUTTON_CONTROLS, "dpiButton"]; + const options = (snapshot.status?.razerButtonOptions ?? RAZER_BUTTON_MAPPINGS) as readonly string[]; + for (const con of order) { const current = mappings[con]; if (!current) continue; rows.push({ key: `razer-button-${con}`, name: RAZER_BUTTON_CONTROL_LABEL[con], current, - options: RAZER_BUTTON_MAPPINGS, + options, // Left Click is fixed on the Standard layer — Synapse enforces the same // restriction, and the driver throws rather than send it. locked: con === RAZER_LOCKED_BUTTON_CONTROL, From 1df220c4f50aeed568144607e1068622f9b8574d Mon Sep 17 00:00:00 2001 From: OpenMouse Bot Date: Fri, 4 Dec 2026 10:40:43 -0700 Subject: [PATCH 3/6] feat(razer): list the wheel press and offer middle click where it is verified --- src/features/devices/cards/AdvancedCards.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/features/devices/cards/AdvancedCards.tsx b/src/features/devices/cards/AdvancedCards.tsx index 96ce84c6..f465e567 100644 --- a/src/features/devices/cards/AdvancedCards.tsx +++ b/src/features/devices/cards/AdvancedCards.tsx @@ -10,7 +10,6 @@ import { type EggSpdtMode, } from "@openmouse/protocol/drivers/endgame/egg-op1-hid"; import { - RAZER_BUTTON_CONTROLS, RAZER_BUTTON_CONTROL_LABEL, RAZER_BUTTON_MAPPINGS, RAZER_KEY_MODIFIERS, @@ -1628,10 +1627,9 @@ export function RazerButtonCard({ snapshot }: { snapshot: ControlSnapshot }): Re if (!mappings) return null; const busy = snapshot.settingInProgress; const rows: Array<{ key: string; name: string; current: string; options: readonly string[]; locked: boolean }> = []; - // The bottom button is a fifth control on models whose firmware stores a - // plain action there rather than the sensitivity toggle; a model that does - // not answer for it simply contributes no row. - const order: RazerButtonControl[] = [...RAZER_BUTTON_CONTROLS, "dpiButton"]; + // The wheel press and the bottom button are model-specific: only a model + // whose firmware answers for them contributes a row. + const order: RazerButtonControl[] = ["leftClick", "scrollClick", "rightClick", "mouse4", "mouse5", "dpiButton"]; const options = (snapshot.status?.razerButtonOptions ?? RAZER_BUTTON_MAPPINGS) as readonly string[]; for (const con of order) { const current = mappings[con]; From cd043021027b50710128145755040e619d22555f Mon Sep 17 00:00:00 2001 From: Onyx Date: Fri, 4 Dec 2026 20:05:40 +0100 Subject: [PATCH 4/6] fix(razer): review findings on the Viper Mini key binding - Toggle rows keep their dropdown: capture mode needs a button control - Capture ends when the active device changes, so a key is never staged on another mouse - F13 to F24 can be captured for Razer bindings; the Incott key list is unchanged - Game profile restores write a keyboard assignment back, turning its label into the key it was made from --- src/device/controller.ts | 11 +++++++---- src/device/incott-macros.ts | 3 ++- src/features/devices/cards/AdvancedCards.tsx | 3 ++- src/shared/hid-keys.test.ts | 20 ++++++++++++++++++++ src/shared/hid-keys.ts | 20 +++++++++++++++++++- 5 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 src/shared/hid-keys.test.ts diff --git a/src/device/controller.ts b/src/device/controller.ts index c2f9f066..a88462dc 100644 --- a/src/device/controller.ts +++ b/src/device/controller.ts @@ -6,6 +6,7 @@ import { cachedBatterySamples, estimateBatteryTime, estimateFromRatedLife, HISTO import { bridgeEmptyResultMessage, isBridgeHidActive } from "../features/bridge/bridge-hid"; import { applyBridgeNativeSettings } from "../features/bridge/bridge"; import { pollingRateText } from "../shared/polling-rate"; +import { keyChordFromLabel } from "../shared/hid-keys"; import { clientSupportScore, createKeyboardClient, @@ -2412,10 +2413,12 @@ export function applyGameProfileSnapshot(snapshot: GameProfileSnapshot): void { for (const [button, action] of Object.entries(s.buttonMappings ?? {})) applyDeviceButtonMapping(button, action); for (const [control, mapping] of Object.entries(s.razerButtonMappings ?? {})) { - // A key assignment reads back as a label like "Ctrl+F13", which cannot be - // replayed: the write needs mods and usage, and a label does not carry them. - if (!(C().RAZER_BUTTON_MAPPINGS as readonly string[]).includes(mapping)) continue; - applyRazerButtonMapping(control as RazerButtonControl, mapping as RazerButtonMapping); + if ((C().RAZER_BUTTON_MAPPINGS as readonly string[]).includes(mapping)) { + applyRazerButtonMapping(control as RazerButtonControl, mapping as RazerButtonMapping); + continue; + } + const key = keyChordFromLabel(mapping, C().razerKeyLabel, Object.values(C().RAZER_KEY_MODIFIERS)); + if (key) applyRazerKeyMapping(control as RazerButtonControl, key); } if (s.finalmouseDongleLedMode != null) applyFinalmouseSetting("dongleLed", s.finalmouseDongleLedMode); diff --git a/src/device/incott-macros.ts b/src/device/incott-macros.ts index 07f90112..7624ec98 100644 --- a/src/device/incott-macros.ts +++ b/src/device/incott-macros.ts @@ -327,7 +327,8 @@ export const INCOTT_MACRO_DEFAULT_ACTION: Readonly macro key. Only the three buttons the table has. */ diff --git a/src/features/devices/cards/AdvancedCards.tsx b/src/features/devices/cards/AdvancedCards.tsx index f465e567..9bec4090 100644 --- a/src/features/devices/cards/AdvancedCards.tsx +++ b/src/features/devices/cards/AdvancedCards.tsx @@ -1600,6 +1600,7 @@ export function RazerButtonCard({ snapshot }: { snapshot: ControlSnapshot }): Re // no keyboard write at all. const keyCapable = control.supportsRazerKeyMapping(); const [capturing, setCapturing] = useState(null); + useEffect(() => setCapturing(null), [snapshot.activeDeviceKey]); useEffect(() => { if (!capturing) return undefined; const onKeyDown = (event: KeyboardEvent): void => { @@ -1701,7 +1702,7 @@ export function RazerButtonCard({ snapshot }: { snapshot: ControlSnapshot }): Re data-pending-key={row.key} > {displayText(locale, row.name)} - {row.locked ? {displayText(locale, row.current)} : capturing === rowControl ? ( + {row.locked ? {displayText(locale, row.current)} : capturing !== null && capturing === rowControl ? ( {t(locale, "adv.pressKey")}