Skip to content

Commit 386fdcb

Browse files
Copilotniels9001noraa-junker
authored
[Shortcut Guide] Render key names instead of raw numeric key codes (#48037)
## Summary of the Pull Request Shortcut Guide was rendering raw numeric key codes in key visuals for some shortcuts (notably generated PowerToys shortcuts), showing numbers where key characters/names were expected. This change normalizes numeric key handling so display output matches actual key labels. ## PR Checklist - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments - **Scope** - Updated `ShortcutDescriptionToKeysConverter` in `ShortcutGuide.Ui` only. - **Behavior change** - Numeric key codes are no longer passed through as raw integers by default. - Arrow keys (`37/38/39/40`) remain numeric to preserve existing glyph rendering behavior. - All other numeric key codes are converted to display names via `Helper.GetKeyName(...)`. - **Result** - Shortcut Guide key caps now show expected characters/key names instead of numeric values for manifest-provided numeric keys. ```csharp if (int.TryParse(key, out int keyCode)) { switch (keyCode) { case 38: case 40: case 37: case 39: shortcutList.Add(keyCode); // keep glyph path break; default: shortcutList.Add(Helper.GetKeyName((uint)keyCode)); // show key label break; } } ``` ## Validation Steps Performed No additional validation details are included in this description. > [!WARNING] > > <details> > <summary>Firewall rules blocked me from connecting to one or more addresses (expand for details)</summary> > > #### I tried to connect to the following addresses, but was blocked by firewall rules: > > - `o3svsblobprodcus318.vsblob.vsassets.io` > - Triggering command: `/usr/bin/dotnet dotnet build /home/REDACTED/work/PowerToys/PowerToys/src/modules/ShortcutGuide/ShortcutGuide.Ui/ShortcutGuide.Ui.csproj -v minimal` (dns block) > > If you need me to access, download, or install something from one of these locations, you can either: > > - Configure [Actions setup steps](https://gh.io/copilot/actions-setup-steps) to set up my environment, which run before the firewall is enabled > - Add the appropriate URLs or hosts to the custom allowlist in this repository's [Copilot coding agent settings](https://github.com/microsoft/PowerToys/settings/copilot/coding_agent) (admins only) > > </details> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com> Co-authored-by: Noraa Junker <noraa.junker@outlook.com>
1 parent 8af6a99 commit 386fdcb

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/modules/ShortcutGuide/ShortcutGuide.Ui/Converters/ShortcutDescriptionToKeysConverter.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,22 @@ public List<object> GetKeysList(ShortcutDescription description)
5858

5959
foreach (var key in description.Keys)
6060
{
61-
// Try to parse a string key number to a VirtualKey
61+
// Try to parse a string key number to a key code
6262
if (int.TryParse(key, out int keyCode))
6363
{
64-
shortcutList.Add(keyCode);
64+
switch (keyCode)
65+
{
66+
// https://learn.microsoft.com/uwp/api/windows.system.virtualkey?view=winrt-20348
67+
case 38: // The Up Arrow key or button.
68+
case 40: // The Down Arrow key or button.
69+
case 37: // The Left Arrow key or button.
70+
case 39: // The Right Arrow key or button.
71+
shortcutList.Add(keyCode);
72+
break;
73+
default:
74+
shortcutList.Add(Microsoft.PowerToys.Settings.UI.Library.Utilities.Helper.GetKeyName((uint)keyCode));
75+
break;
76+
}
6577
}
6678
else
6779
{

0 commit comments

Comments
 (0)