diff --git a/src/hid-usage-name-overrides.json b/src/hid-usage-name-overrides.json index f2773ff5..88c64247 100644 --- a/src/hid-usage-name-overrides.json +++ b/src/hid-usage-name-overrides.json @@ -8,16 +8,16 @@ "35": { "short": "6" }, "36": { "short": "7" }, "37": { "short": "8" }, - "38": { "short": "9" }, - "39": { "short": "0" }, - "40": { "short": "Ret", "med": "Return" }, + "38": { "short": "9", "Name":"Keyboard 9 and Left Parenthesis"}, + "39": { "short": "0", "Name":"Keyboard 9 and Right Parenthesis"}, + "40": { "short": "⏎Ret", "med": "Return", "Name":"Keyboard Return/Enter"}, "41": { "short": "Esc", "long": "Escape" }, - "42": { "short": "BkSp", "med": "BkSpc", "long": "Backspace" }, + "42": { "short": "BkSp", "med": "BkSpc", "long": "Backspace", "Name": "Keyboard Backspace"}, "44": { "short": "␣", "med": "Space" }, "45": { "short": "-", "med": "Dash" }, "46": { "short": "=", "med": "Equals" }, - "47": { "short": "{" }, - "48": { "short": "}" }, + "47": { "short": "[", "Name": "Keyboard Left Bracket and Brace" }, + "48": { "short": "]", "Name": "Keyboard Right Bracket and Brace" }, "49": { "short": "\\" }, "50": { "short": "NUHS", "long": "NonUS Hash" }, "51": { "short": ";" }, @@ -60,15 +60,16 @@ "100": { "short": "NUBS" }, "103": { "short": "=" }, "133": { "short": "," }, + "158": { "Name": "Keyboard Non-PC Return"}, "134": { "short": "=" }, "176": { "short": "00" }, "177": { "short": "000" }, "224": { "short": "Ctrl", "med": "L Ctrl" }, - "225": { "short": "Shft", "med": "L Shft", "long": "L Shift" }, + "225": { "short": "⇧Shft", "med": "L Shft", "long": "L Shift" }, "226": { "short": "Alt", "med": "L Alt", "long": "Left Alt" }, "227": { "short": "GUI", "med": "L GUI", "long": "Left GUI" }, "228": { "short": "Ctrl", "med": "R Ctrl" }, - "229": { "short": "Shft", "med": "R Shft", "long": "R Shift" }, + "229": { "short": "Shft⇧", "med": "R Shft", "long": "R Shift" }, "230": { "short": "AltG", "med": "AltGr" }, "231": { "short": "GUI", "med": "R GUI", "long": "Right GUI" } }, diff --git a/src/hid-usages.ts b/src/hid-usages.ts index a3e3dd84..93e8457e 100644 --- a/src/hid-usages.ts +++ b/src/hid-usages.ts @@ -7,6 +7,7 @@ interface HidLabels { short?: string; med?: string; long?: string; + Name?: string; } const overrides: Record> = HidOverrides; @@ -30,16 +31,27 @@ export const hid_usage_page_and_id_from_usage = ( export const hid_usage_page_get_ids = ( usage_page: number -): UsagePageInfo | undefined => UsagePages.find((p) => p.Id === usage_page); +): UsagePageInfo | undefined => { -export const hid_usage_get_label = ( - usage_page: number, - usage_id: number -): string | undefined => - overrides[usage_page.toString()]?.[usage_id.toString()]?.short || - UsagePages.find((p) => p.Id === usage_page)?.UsageIds?.find( - (u) => u.Id === usage_id - )?.Name; + // Fetch the relevant usage page from the core keyboard/consumer usage tables + const usagePageInfo = UsagePages.find((p) => p.Id === usage_page); + + // Filter overrides to include only entries with a valid override key of Name + const filteredOverrides = Object.fromEntries( + Object.entries(overrides[usage_page])?.filter( + ([_, overrideData]) => overrideData.Name + ) + ); + + // Mutate the usagePageInfo with the discovered "Name" overrides + for (const key in filteredOverrides) { + const usageId = usagePageInfo?.UsageIds.find((p) => p.Id === parseInt(key)); + if (usageId) { + usageId.Name = filteredOverrides[key].Name as string; + } + } + return usagePageInfo; +}; export const hid_usage_get_labels = ( usage_page: number,