Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

KeyGesture Class

Defines a keyboard combination that can be used to invoke a command.

Namespace: System.Windows.Input
Assembly: PresentationCore (in presentationcore.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[TypeConverterAttribute(typeof(KeyGestureConverter))] 
public class KeyGesture : InputGesture
/** @attribute TypeConverterAttribute(System.Windows.Input.KeyGestureConverter) */ 
public class KeyGesture extends InputGesture
TypeConverterAttribute(System.Windows.Input.KeyGestureConverter) 
public class KeyGesture extends InputGesture
<KeyGesture .../>
<object property="Key"/>
- or -
<object property="oneOrMoreModifierKeys"/>
- or -
<object property="Key+oneOrMoreModifierKeys"/>

 Key   Key  A single key.  For more information, see the Key property.  oneOrMoreModifierKeys  One or more modifier keys, defined by the ModifierKeys enumeration, delimited with a "+" character.  For more information, see the Modifiers property. 

In most cases, a KeyGesture must be associated with one or more ModifierKeys. The exceptions to this rule are the function keys and the numeric keypad keys, which can be a valid KeyGesture by themselves. For example, you can create a KeyGesture by using only the F12 key, but to use the X key in a KeyGesture it must be paired with a modifier key.

You can use a KeyBinding to bind a KeyGesture to an ICommand, so that the command is invoked when the KeyGesture occurs.

The following example shows how to bind the Close command to a KeyGesture using a KeyBinding.

<KeyBinding Modifiers="Alt"
            Key="L"
            Command="ApplicationCommands.Close" />

KeyGesture CloseCmdKeyGesture = new KeyGesture(
    Key.L, ModifierKeys.Alt);

KeyBinding CloseKeyBinding = new KeyBinding(
    ApplicationCommands.Close, CloseCmdKeyGesture);

this.InputBindings.Add(CloseKeyBinding);

System.Object
   System.Windows.Input.InputGesture
    System.Windows.Input.KeyGesture

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft