Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the mapping of OEM keys ({}|\<>/_-=+) in key bindings #2067

Merged
merged 2 commits into from
Jul 23, 2019

Conversation

DHowett-MSFT
Copy link
Contributor

@DHowett-MSFT DHowett-MSFT commented Jul 23, 2019

This commit introduces support for key bindings containing keys
traditionally classified as "OEM" keys. It uses VkKeyScanW and
MapVirtualKeyW, and translates the modifiers that come out of
VkKeyScanW to key chord modifiers.

The net result of this is that you can use bindings like "ctrl+|" in
your settings. That one in particular will be reserialized (and
displayed in any menus) as "ctrl+shift+". Admittedly, this is not
clear, but it is the truest representation of the key.

This commit also moves the Xaml key chord name override generator into
App as a static function, AND it forces its use for all modifier
names. This will present a localization issue, which will be helped in
part by #1972. This is required to work around
microsoft/microsoft-ui-xaml#708. I've kept the original code around
guarded by a puzzling ifdef, because it absolutely has value.

Fixes #1212.

image

Renormalization

input reserialized as
"alt+=" "alt+plus"
"alt+:" "alt+shift+;"
"ctrl+?" "ctrl+shift+/"
"shift+~" "shift+<backtick>"
(markdown limitation)
"alt+}" "alt+shift+]"
"ctrl+alt+<pipe>" "ctrl+alt+shift+\\"
"shift+\"" "shift+'"
"alt+," "alt+,"
"ctrl+-" "ctrl+-"
"shift+." "shift+."

PR Checklist

Validation Steps Performed

Manual

This commit introduces support for key bindings containing keys
traditionally classified as "OEM" keys. It uses VkKeyScanW and
MapVirtualKeyW, and translates the modifiers that come out of
VkKeyScanW to key chord modifiers.

The net result of this is that you can use bindings like "ctrl+|" in
your settings. That one in particular will be reserialized (and
displayed in any menus) as "ctrl+shift+\". Admittedly, this is not
clear, but it _is_ the truest representation of the key.

This commit also moves the Xaml key chord name override generator into
App as a static function, *AND* it forces its use for all modifier
names. This will present a localization issue, which will be helped in
part by #1972. This is required to work around
microsoft/microsoft-ui-xaml#708. I've kept the original code around
guarded by a puzzling ifdef, because it absolutely has value.

Fixes #1212.
@DHowett-MSFT
Copy link
Contributor Author

I reckon @shanselman will like this. Also, it makes ctrl+shift+| work as a passable key binding for splitVertical!

Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

God bless you for fixing this one. I think I'm a little confused by the whole DEP_MICROSOFT_UI_XAML_708_FIXED thing - maybe coffee hasn't kicked in quite yet. I'm otherwise fine with this.

// Method Description:
// - Takes a MenuFlyoutItem and a corresponding KeyChord value and creates the accelerator for UI display.
// Takes into account a special case for an error condition for a comma
// Arguments:
// - MenuFlyoutItem that will be displayed, and a KeyChord to map an accelerator
void App::_SetAcceleratorForMenuItem(Windows::UI::Xaml::Controls::MenuFlyoutItem& menuItem, const winrt::Microsoft::Terminal::Settings::KeyChord& keyChord)
{
#ifdef DEP_MICROSOFT_UI_XAML_708_FIXED
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this right?
Until 708 is fixed, always use the KeyboardAcceleratorTextOverride method.
When 708 is fixed, if it's not a comma, set the Keyboard accelerator. If it is a comma, still use the override thing.

Would we still need the else when 708 is fixed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd probably yank the comma check as well, and the other accelerator formatting code. I wanted this diff to be "approximately" minimal, however

@shanselman
Copy link
Member

shanselman commented Jul 23, 2019 via email

@DHowett-MSFT DHowett-MSFT merged commit 2407828 into master Jul 23, 2019
@DHowett-MSFT DHowett-MSFT deleted the dev/duhowett/oemvk branch July 23, 2019 21:05
@ghost
Copy link

ghost commented Aug 3, 2019

🎉Windows Terminal Preview v0.3.2142.0 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Figure out how to support bindings for "VK_OEM" keys
5 participants