From b0ed16b6436c3ba79fa1d0160966a86adf0d1fe3 Mon Sep 17 00:00:00 2001 From: Anthony Tan Date: Tue, 14 Jan 2025 10:13:09 -0500 Subject: [PATCH 1/6] Allow Name overrides in dataset returned to picker --- src/hid-usages.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/hid-usages.ts b/src/hid-usages.ts index a3e3dd8..d4c017d 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,7 +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 => { + + // 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_label = ( usage_page: number, From 7a49ed0929b2248adaee9ebb3dcb37346036f285 Mon Sep 17 00:00:00 2001 From: Anthony Tan Date: Tue, 14 Jan 2025 10:14:33 -0500 Subject: [PATCH 2/6] Remove unused function --- src/hid-usages.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/hid-usages.ts b/src/hid-usages.ts index d4c017d..93e8457 100644 --- a/src/hid-usages.ts +++ b/src/hid-usages.ts @@ -53,15 +53,6 @@ export const hid_usage_page_get_ids = ( return usagePageInfo; }; -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; - export const hid_usage_get_labels = ( usage_page: number, usage_id: number From 81f78507e57d9dab97f1ecce12c67a9675bf6d50 Mon Sep 17 00:00:00 2001 From: Anthony Tan Date: Tue, 14 Jan 2025 10:16:25 -0500 Subject: [PATCH 3/6] Update the display for brackets/parentheses. - fixes #100 --- src/hid-usage-name-overrides.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hid-usage-name-overrides.json b/src/hid-usage-name-overrides.json index f2773ff..ddd9955 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" }, + "38": { "short": "9", "Name":"Keyboard 9 and Left Parenthesis"}, + "39": { "short": "0", "Name":"Keyboard 9 and Right Parenthesis"}, "40": { "short": "Ret", "med": "Return" }, "41": { "short": "Esc", "long": "Escape" }, "42": { "short": "BkSp", "med": "BkSpc", "long": "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": ";" }, From 78cb28bc156e0a9d1347f3a249de54cc608ce562 Mon Sep 17 00:00:00 2001 From: Anthony Tan Date: Tue, 14 Jan 2025 10:36:24 -0500 Subject: [PATCH 4/6] Add variation for Lshift/Rshift. --- src/hid-usage-name-overrides.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hid-usage-name-overrides.json b/src/hid-usage-name-overrides.json index ddd9955..0886474 100644 --- a/src/hid-usage-name-overrides.json +++ b/src/hid-usage-name-overrides.json @@ -64,11 +64,11 @@ "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" } }, From 09c4716aacda9602fa1e61c8f5e67a86d332d568 Mon Sep 17 00:00:00 2001 From: Anthony Tan Date: Tue, 14 Jan 2025 10:38:10 -0500 Subject: [PATCH 5/6] More distinguishment on the Return HID code. - the one you actually want has a symbol in the editor and the name tweaked - the one you probably don't want has a name change to hopefully show that it's not expected. --- src/hid-usage-name-overrides.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hid-usage-name-overrides.json b/src/hid-usage-name-overrides.json index 0886474..73aeb62 100644 --- a/src/hid-usage-name-overrides.json +++ b/src/hid-usage-name-overrides.json @@ -10,7 +10,7 @@ "37": { "short": "8" }, "38": { "short": "9", "Name":"Keyboard 9 and Left Parenthesis"}, "39": { "short": "0", "Name":"Keyboard 9 and Right Parenthesis"}, - "40": { "short": "Ret", "med": "Return" }, + "40": { "short": "⏎Ret", "med": "Return", "Name":"Keyboard Return/Enter"}, "41": { "short": "Esc", "long": "Escape" }, "42": { "short": "BkSp", "med": "BkSpc", "long": "Backspace" }, "44": { "short": "␣", "med": "Space" }, @@ -60,6 +60,7 @@ "100": { "short": "NUBS" }, "103": { "short": "=" }, "133": { "short": "," }, + "158": { "Name": "Keyboard Non-PC Return"}, "134": { "short": "=" }, "176": { "short": "00" }, "177": { "short": "000" }, From d048b12aa628a927fba09945398f457c405fc5e8 Mon Sep 17 00:00:00 2001 From: Anthony Tan Date: Tue, 14 Jan 2025 10:44:32 -0500 Subject: [PATCH 6/6] Update name of the 'regular' delete key. - Backspace is by far the more common search term and will now show this key (rather than just the keypad one) --- src/hid-usage-name-overrides.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hid-usage-name-overrides.json b/src/hid-usage-name-overrides.json index 73aeb62..88c6424 100644 --- a/src/hid-usage-name-overrides.json +++ b/src/hid-usage-name-overrides.json @@ -12,7 +12,7 @@ "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" },