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

WinUI crashes when attempting to use Oemcomma as Key in accelerator #708

Closed
timheuer opened this issue May 14, 2019 · 5 comments
Closed
Labels
area-KeyboardAccelerators needs-winui-3 Indicates that feature can only be done in WinUI 3.0 or beyond. (needs winui 3) no-issue-activity product-winui2 team-Reach Issue for the Reach team

Comments

@timheuer
Copy link
Member

Confirmed bug with product team.

Description

When creating a KeyboardAccelerator with a Modifier and Key, the runtime will crash when attempting to use a comma as the key.

Repro Steps

Create a UWP blank app
XAML:

<Grid>
        <Button Content="CLICK ME">
            <Button.Flyout>
                <MenuFlyout Placement="Right">
                    <MenuFlyoutItem Text="Settings" x:Name="foo" />
                </MenuFlyout>
            </Button.Flyout>
        </Button>
    </Grid>

C#:

public MainPage()
        {
            this.InitializeComponent();

            // creating this in code because VirtualKey.Oemcomma is not in the enum
            KeyboardAccelerator ka = new KeyboardAccelerator();
            ka.Key = (VirtualKey)188; // 188 is mapped to VK_OEM_COMMA
            ka.Modifiers = VirtualKeyModifiers.Control | VirtualKeyModifiers.Shift;
            foo.KeyboardAccelerators.Add(ka);
        }

Expected

Button launches a flyout with a menu item showing "Control + ," as the label

Actual

Crashes at:
Windows.UI.Xaml.dll!GetResourceStringIdFromVirtualKey(Windows::System::VirtualKey key) Line 330 C++
Windows.UI.Xaml.dll!DirectUI::KeyboardAccelerator::ConcatVirtualKey(Windows::System::VirtualKey key, Windows::Internal::String & keyboardAcceleratorString) Line 126 C++
Windows.UI.Xaml.dll!DirectUI::KeyboardAccelerator::GetStringRepresentation(HSTRING__ * * stringRepresentation) Line 116 C++
Windows.UI.Xaml.dll!DirectUI::KeyboardAccelerator::GetStringRepresentationForUIElement(DirectUI::UIElement * uiElement, HSTRING__ * * stringRepresentation) Line 78 C++
Windows.UI.Xaml.dll!DirectUI::MenuFlyoutItem::get_KeyboardAcceleratorTextOverrideImpl(HSTRING__ * * pValue) Line 851 C++

when trying to lookup the resource for the comma character.

@Austin-Lamb
Copy link

Thanks for reporting this - we have a bug in how we look up the localized string for the VK_OEM_COMMA accelerator. To workaround this for now, you can provide your own string in MenuFlyoutItem.KeyboardAcceleratorTextOverride property, which prevents us from trying to create our string.

This bug is in the framework rather than the controls, so we can't fix this directly in WinUI yet - but will try to look into it for WinUI 3.

DHowett-MSFT pushed a commit to microsoft/terminal that referenced this issue 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.
DHowett-MSFT pushed a commit to microsoft/terminal that referenced this issue 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.
@DHowett-MSFT
Copy link

FWIW, this happens for almost all VK_OEM keys.

DHowett-MSFT pushed a commit to microsoft/terminal that referenced this issue 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.
@Austin-Lamb
Copy link

@DHowett-MSFT - yeah, the bug is about a range check we do. Can you please add to this issue the list of all the VK_* entries that you'd want supported so we're sure to get them all when we address this?

@Austin-Lamb Austin-Lamb added the needs-winui-3 Indicates that feature can only be done in WinUI 3.0 or beyond. (needs winui 3) label Aug 26, 2019
@jevansaks jevansaks added the team-Reach Issue for the Reach team label Nov 7, 2019
@SparkieLabs
Copy link

SparkieLabs commented Feb 3, 2020

This issue means that you can't use the common key shortcuts ctrl+= (VK_OEM_PLUS) and ctrl+- (VK_OEM_MINUS) to zoom in and out, would be great if it was fixed in WinUI 3.

donno2048 added a commit to donno2048/terminal that referenced this issue Sep 28, 2020
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.
@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-KeyboardAccelerators needs-winui-3 Indicates that feature can only be done in WinUI 3.0 or beyond. (needs winui 3) no-issue-activity product-winui2 team-Reach Issue for the Reach team
Projects
None yet
Development

No branches or pull requests

6 participants