How to add keyboard shortcut of OEM keys in Keyboard Accelerators in WinUI 3, XAML

Hemanth B 886 Reputation points
2024-01-08T13:14:13.2866667+00:00

Hi. I am creating an app in WinUI 3, C# Xaml. In the app I have a button which has the "+" symbol. The Keyboard shortcut for the button is only showing the numeric pad "+" key. How do I add a shortcut of the shift key and the OEM plus key? I've explored a bit online and found out that there is no Virtual Key for the OEM keys. Is there any workaround for this? Or can I set a keyboard shortcut using the enum value of the keys. Kindly help.

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
743 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,493 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,561 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
781 questions
0 comments No comments
{count} votes

Accepted answer
  1. Xiaopo Yang - MSFT 12,151 Reputation points Microsoft Vendor
    2024-01-09T02:12:23.01+00:00

    According to Localize the accelerators,

    Keyboard accelerators are implemented as virtual-keys. Localized accelerators must be chosen from the predefined collection of Virtual-Key codes (otherwise, a XAML parser error will occur).

    and

    VK_OEM_PLUS 0xBB For any country/region, the + key

    You can set VK_OEM_PLUS programmatically.

            myButton.KeyboardAccelerators.Add(new Microsoft.UI.Xaml.Input.KeyboardAccelerator()
            {
                Key = (Windows.System.VirtualKey)0xBB,
                Modifiers = Windows.System.VirtualKeyModifiers.Control
            });
    

0 additional answers

Sort by: Most helpful