scancodes in command palette #16358

Open
opened 2026-01-31 05:05:08 +00:00 by claunia · 5 comments
Owner

Originally created by @stanciuadrian on GitHub (Jan 9, 2022).

Windows Terminal version

12.3472.0

Windows build number

10.0.22000.376

Other Software

No response

Steps to reproduce

Press ctrl+shift+p
Type "qua"
Notice the "Summon Quake window" shortcut

Expected Behavior

The shortcut text should be "Win + `". I don't know the scancodes by heart.

Actual Behavior

The shortcut text is: win + sc(41).

Originally created by @stanciuadrian on GitHub (Jan 9, 2022). ### Windows Terminal version 12.3472.0 ### Windows build number 10.0.22000.376 ### Other Software _No response_ ### Steps to reproduce Press ctrl+shift+p Type "qua" Notice the "Summon Quake window" shortcut ### Expected Behavior The shortcut text should be "Win + `". I don't know the scancodes by heart. ### Actual Behavior The shortcut text is: `win + sc(41)`.
Author
Owner

@zadjii-msft commented on GitHub (Jan 10, 2022):

Huh. This is a good point. We switched that to being bound to a scancode instead of the character, so that it would work on non-en-US layouts the same, but the sc() notation is a little hard to parse.

I wonder if there's a way for us to store the sc internally, but still display the character in the SUI&cmdpal...

@zadjii-msft commented on GitHub (Jan 10, 2022): Huh. This is a good point. We switched that to being bound to a scancode instead of the character, so that it would work on non-en-US layouts the same, but the `sc()` notation is a little hard to parse. I wonder if there's a way for us to store the `sc` internally, but still display the character in the SUI&cmdpal...
Author
Owner

@mauve commented on GitHub (Jan 30, 2022):

you can convert the scancode to a keyname using the win32 API GetKeyNameText() which works but has a somewhat annoying API, here is an example which converts the example in the issue report sc(41) to `:

std::string scan_code_to_string(unsigned int scan_code)
{
    std::vector<char> buffer;
    buffer.resize(64);
    if (!GetKeyNameTextA(
            static_cast<unsigned long>(scan_code) << 16,
            buffer.data(),
            static_cast<int>(buffer.size())))
    {
        throw std::runtime_error{"cannot get key name"};
    }

    return {buffer.data()};
}

When run in a very small hack program I get the following output:

Keyboard Layout ENG-US:

image

If I switch to layout German:

image

@mauve commented on GitHub (Jan 30, 2022): you can convert the scancode to a keyname using the win32 API `GetKeyNameText()` which works but has a somewhat annoying API, here is an example which converts the example in the issue report `sc(41)` to `` ` ``: ```cpp std::string scan_code_to_string(unsigned int scan_code) { std::vector<char> buffer; buffer.resize(64); if (!GetKeyNameTextA( static_cast<unsigned long>(scan_code) << 16, buffer.data(), static_cast<int>(buffer.size()))) { throw std::runtime_error{"cannot get key name"}; } return {buffer.data()}; } ``` When run in a very small hack program I get the following output: Keyboard Layout ENG-US: ![image](https://user-images.githubusercontent.com/795800/151704624-4f64a3cf-1ee1-405d-b2d9-df94db2c8418.png) If I switch to layout German: ![image](https://user-images.githubusercontent.com/795800/151705166-3aedb529-d43d-45cf-87c6-321d14c79f73.png)
Author
Owner

@mauve commented on GitHub (Jan 30, 2022):

Maybe I can fix this, but I haven't touched the code in quite some while, is this the line where the conversion would need to happen https://github.com/microsoft/terminal/blob/main/src/cascadia/TerminalApp/ActionPaletteItem.cpp#L41?

Maybe something like this? @DHowett

-        item->KeyChordText(senderCommand.KeyChordText());
+        item->KeyChordText(find_and_replace_scancodes(senderCommand.KeyChordText()));

If you point me in the correct direction I can whip up a patch next weekend.

@mauve commented on GitHub (Jan 30, 2022): Maybe I can fix this, but I haven't touched the code in quite some while, is this the line where the conversion would need to happen https://github.com/microsoft/terminal/blob/main/src/cascadia/TerminalApp/ActionPaletteItem.cpp#L41? Maybe something like this? @DHowett ```cpp - item->KeyChordText(senderCommand.KeyChordText()); + item->KeyChordText(find_and_replace_scancodes(senderCommand.KeyChordText())); ``` If you point me in the correct direction I can whip up a patch next weekend.
Author
Owner

@DHowett commented on GitHub (Jan 31, 2022):

this looks great to me! if it ends up being the wrong place, we can iterate on it together in the PR :)

@DHowett commented on GitHub (Jan 31, 2022): this looks great to me! if it ends up being the wrong place, we can iterate on it together in the PR :)
Author
Owner

@mauve commented on GitHub (Feb 20, 2022):

@DHowett I created a PR, it works on my machine :) not super-happy with the code, but it works.

@mauve commented on GitHub (Feb 20, 2022): @DHowett I created a PR, it works on my machine :) not super-happy with the code, but it works.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#16358