KeyboardAccelerator KeyboardAccelerator KeyboardAccelerator KeyboardAccelerator Class

Definition

Some information relates to pre-released product which may be substantially modified before it’s commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Prerelease APIs are identified by a Prerelease label.

[Contains prerelease APIs.]
Represents a keyboard shortcut (or accelerator) that lets a user perform an action using the keyboard instead of navigating the app UI (directly or through access keys).

Accelerators are typically assigned to buttons or menu items.

public : class KeyboardAccelerator : DependencyObject, IKeyboardAcceleratorpublic class KeyboardAccelerator : DependencyObject, IKeyboardAcceleratorPublic Class KeyboardAccelerator Inherits DependencyObject Implements IKeyboardAccelerator// This API is not available in Javascript.
Inheritance
KeyboardAcceleratorKeyboardAcceleratorKeyboardAcceleratorKeyboardAccelerator
Attributes
Windows 10 requirements
Device family
Windows 10 Insider Preview (introduced v10.0.16257.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v5)

Inherited Members

Inherited methods

Inherited properties

Remarks

An accelerator key can be a single key, such as F1 - F12 and Esc, or a combination of keys (Ctrl + Shift + B, or Ctrl C) that invoke a command. They differ from access keys (mnemonics), which are typically modified with the Alt key and simply activate a command or control.

An accelerator can be executed even if the element associated with the accelerator is not visible. For example, an item in the SecondaryCommands collection of the CommandBar can be invoked using an accelerator without expanding the overflow menu and displaying the element.

By default, an accelerator has global scope. However, you can constrain scope using ScopeOwner or disable an accelerator completely using IsEnabled.

Constructors

KeyboardAccelerator() KeyboardAccelerator() KeyboardAccelerator() KeyboardAccelerator()

Prerelease. Initializes a new instance of the KeyboardAccelerator class.

public : KeyboardAccelerator()public KeyboardAccelerator()Public Sub New()// This API is not available in Javascript.

Properties

IsEnabled IsEnabled IsEnabled IsEnabled

Prerelease. Gets or sets whether a keyboard shortcut (accelerator) is available to the user.

public : PlatForm::Boolean IsEnabled { get; set; }public bool IsEnabled { get; set; }Public ReadWrite Property IsEnabled As bool// This API is not available in Javascript.
Value
PlatForm::Boolean bool bool bool

true if the shortcut is available; otherwise, false.

IsEnabledProperty IsEnabledProperty IsEnabledProperty IsEnabledProperty

Prerelease. Identifies the IsEnabled dependency property.

public : static DependencyProperty IsEnabledProperty { get; }public static DependencyProperty IsEnabledProperty { get; }Public Static ReadOnly Property IsEnabledProperty As DependencyProperty// This API is not available in Javascript.
Value
DependencyProperty DependencyProperty DependencyProperty DependencyProperty

The identifier for the IsEnabled dependency property.

Key Key Key Key

Prerelease. Gets or sets the virtual key (used in conjunction with one or more modifier keys) for a keyboard shortcut (accelerator).

A keyboard shortcut is invoked when the modifier keys asssociated with the shortcut are pressed and then the non-modifier key is pressed at the same time. For example, Ctrl+C for copy and Ctrl+S for save.

public : VirtualKey Key { get; set; }public VirtualKey Key { get; set; }Public ReadWrite Property Key As VirtualKey// This API is not available in Javascript.
Value
VirtualKey VirtualKey VirtualKey VirtualKey

The virtual key.

KeyProperty KeyProperty KeyProperty KeyProperty

Prerelease. Identifies the Key dependency property.

public : static DependencyProperty KeyProperty { get; }public static DependencyProperty KeyProperty { get; }Public Static ReadOnly Property KeyProperty As DependencyProperty// This API is not available in Javascript.
Value
DependencyProperty DependencyProperty DependencyProperty DependencyProperty

The identifier for the Key dependency property.

Modifiers Modifiers Modifiers Modifiers

Prerelease. Gets or sets the virtual key used to modify another keypress for a keyboard shortcut (accelerator).

A keyboard shortcut is invoked when the modifier keys asssociated with the shortcut are pressed and then the non-modifier key is pressed at the same time. For example, Ctrl+C for copy and Ctrl+S for save.

public : VirtualKeyModifiers Modifiers { get; set; }public VirtualKeyModifiers Modifiers { get; set; }Public ReadWrite Property Modifiers As VirtualKeyModifiers// This API is not available in Javascript.

ModifiersProperty ModifiersProperty ModifiersProperty ModifiersProperty

Prerelease. Identifies the Modifiers dependency property.

public : static DependencyProperty ModifiersProperty { get; }public static DependencyProperty ModifiersProperty { get; }Public Static ReadOnly Property ModifiersProperty As DependencyProperty// This API is not available in Javascript.
Value
DependencyProperty DependencyProperty DependencyProperty DependencyProperty

The identifier for the Modifiers dependency property.

ScopeOwner ScopeOwner ScopeOwner ScopeOwner

Prerelease. Gets or sets the scope (or target) of the keyboard accelerator.

public : DependencyObject ScopeOwner { get; set; }public DependencyObject ScopeOwner { get; set; }Public ReadWrite Property ScopeOwner As DependencyObject// This API is not available in Javascript.
Value
DependencyObject DependencyObject DependencyObject DependencyObject

The default is null (global scope).

Examples

This example demonstrates how to create a scoped accelerator. The Ctrl+Menu+S accelerator is invoked only if the focus is on a child of MainGrid.

<Grid x:Name="MainGrid">
    …
    <Button Content="Save" Click="OnSave">
        <Button.KeyboardAccelerators>
            <KeyboardAccelerator 
                Key="S"
                Modifiers="Control, Menu"
                ScopeOwner="{x:Bind MainGrid}" />
        </Button.KeyboardAccelerators>
    </Button>
    …
</Grid>
<Grid x:Name="SecondaryGrid"> >
    …
    <Button Content="Edit" Click Click="OnEdit"/>
    …
</Grid>

Remarks

By default, an accelerator has global scope. However, you can constrain scope using ScopeOwner or disable an accelerator completely using IsEnabled.

ScopeOwnerProperty ScopeOwnerProperty ScopeOwnerProperty ScopeOwnerProperty

Prerelease. Identifies the ScopeOwner dependency property.

public : static DependencyProperty ScopeOwnerProperty { get; }public static DependencyProperty ScopeOwnerProperty { get; }Public Static ReadOnly Property ScopeOwnerProperty As DependencyProperty// This API is not available in Javascript.
Value
DependencyProperty DependencyProperty DependencyProperty DependencyProperty

The identifier for the ScopeOwner dependency property.

Events

Invoked Invoked Invoked Invoked

Prerelease. Occurs when the key combination for this KeyboardAccelerator is pressed.

public : event TypedEventHandler Invoked<KeyboardAccelerator,  KeyboardAcceleratorInvokedEventArgs>public event TypedEventHandler Invoked<KeyboardAccelerator,  KeyboardAcceleratorInvokedEventArgs>Public Event Invoked<KeyboardAccelerator,  KeyboardAcceleratorInvokedEventArgs>// This API is not available in Javascript.