Keyboard Keyboard Keyboard Keyboard Class

Definición

Representa el dispositivo de teclado.Represents the keyboard device.

public ref class Keyboard abstract sealed
public static class Keyboard
type Keyboard = class
Public Class Keyboard
Herencia
KeyboardKeyboardKeyboardKeyboard

Ejemplos

En el ejemplo siguiente se muestra cómo utilizar IsKeyToggled el método para determinar si una clave está en estado de alternancia.The following example shows how to use the IsKeyToggled method to determine if a key is in the toggled state. Si se Key cambia el IsKeyToggled que se pasa a, se cambia el fondo de un botón.If the Key passed to IsKeyToggled is toggled, the background of a button is changed.

// Uses the Keyboard.IsToggled to determine if a key is toggled.
if (Keyboard.IsKeyToggled(Key.Return))
{
    btnIsToggle.Background = Brushes.Red;
}
else
{
    btnIsToggle.Background = Brushes.AliceBlue;
}
' Uses the Keyboard.IsToggled to determine if a key is toggled.
If Keyboard.IsKeyToggled(Key.Return) Then
    btnIsToggle.Background = Brushes.Red
Else
    btnIsToggle.Background = Brushes.AliceBlue
End If

Comentarios

La Keyboard clase proporciona eventos, métodos y propiedades relacionados con el teclado que proporcionan información sobre el estado del teclado.The Keyboard class provides keyboard-related events, methods, and properties that provide information regarding the state of the keyboard.

Cada uno de los eventos Keyboard que define como un evento adjunto también se vuelve a exponer mediante las clases UIElement de elementos ContentElement base y como un nuevo evento enrutado.Each of the events that Keyboard defines as an attached event is also re-exposed by the base element classes UIElement and ContentElement as a new routed event. Por lo general, es más conveniente controlar los eventos de teclado para una UIElement aplicación ContentElementen y, en lugar Keyboard de usar los eventos.Generally, it is more convenient to handle keyboard events for an application on UIElement and ContentElement, rather than using the Keyboard events. Para obtener más información, consulte Introducción a la entrada.For details, see Input Overview.

Para que un elemento reciba la entrada del teclado, el elemento debe poder recibir el foco.In order for an element to receive keyboard input, the element must be focusable. La UIElement mayoría de los objetos derivados pueden recibir el foco de forma predeterminada.Most UIElement derived objects are focusable by default. De lo contrario, para que un elemento pueda recibir el Focusable foco, establezca la propiedad del trueelemento base en.Otherwise, to make an element focusable, set the Focusable property on the base element to true. Para obtener más información sobre los elementos base, consulte información general sobre elementos base.For more information on the base elements, see Base Elements Overview.

Panellas clases, StackPanel como y Canvas, establecen el valor predeterminado de Focusable en false.Panel classes, such as StackPanel and Canvas, set the default value of Focusable to false. Por lo tanto, para que estos objetos obtengan Focusable el foco de teclado true, debe establecerse en.Therefore, for these objects to obtain keyboard focus, Focusable must be set to true.

El foco de teclado hace referencia al objeto que recibe la entrada del teclado.Keyboard focus refers to the object that is receiving keyboard input. El elemento con el foco de IsKeyboardFocused teclado tiene trueestablecido en.The element with keyboard focus has IsKeyboardFocused set to true. Solo puede haber un elemento con el foco de teclado en todo el escritorio.There can be only one element with keyboard focus on the entire desktop. El foco lógico hace referencia al objeto dentro de un ámbito de foco que tiene el foco.Logical focus refers to the object within a focus scope that has focus. Para obtener más información sobre el foco, el foco de teclado y el foco lógico, vea Introducción a la entrada e información general sobre el foco.For more information on focus, keyboard focus, and logical focus, see Input Overview and Focus Overview.

Los miembros estáticos de Keyboard la clase delegan en KeyboardDevice la principal del subproceso que realiza la llamada, por lo que no tienen por qué ser seguros para subprocesos.The static members of the Keyboard class delegate to the primary KeyboardDevice of the calling thread, so they are not necessarily thread-safe.

Campos

GotKeyboardFocusEvent GotKeyboardFocusEvent GotKeyboardFocusEvent GotKeyboardFocusEvent

Identifica el evento adjunto GotKeyboardFocus.Identifies the GotKeyboardFocus attached event.

KeyboardInputProviderAcquireFocusEvent KeyboardInputProviderAcquireFocusEvent KeyboardInputProviderAcquireFocusEvent KeyboardInputProviderAcquireFocusEvent

Identifica el evento adjunto KeyboardInputProviderAcquireFocus.Identifies the KeyboardInputProviderAcquireFocus attached event.

KeyDownEvent KeyDownEvent KeyDownEvent KeyDownEvent

Identifica el evento adjunto KeyDown.Identifies the KeyDown attached event.

KeyUpEvent KeyUpEvent KeyUpEvent KeyUpEvent

Identifica el evento adjunto KeyUp.Identifies the KeyUp attached event.

LostKeyboardFocusEvent LostKeyboardFocusEvent LostKeyboardFocusEvent LostKeyboardFocusEvent

Identifica el evento adjunto LostKeyboardFocus.Identifies the LostKeyboardFocus attached event.

PreviewGotKeyboardFocusEvent PreviewGotKeyboardFocusEvent PreviewGotKeyboardFocusEvent PreviewGotKeyboardFocusEvent

Identifica el evento adjunto PreviewGotKeyboardFocus.Identifies the PreviewGotKeyboardFocus attached event.

PreviewKeyboardInputProviderAcquireFocusEvent PreviewKeyboardInputProviderAcquireFocusEvent PreviewKeyboardInputProviderAcquireFocusEvent PreviewKeyboardInputProviderAcquireFocusEvent

Identifica el evento adjunto PreviewKeyboardInputProviderAcquireFocus.Identifies the PreviewKeyboardInputProviderAcquireFocus attached event.

PreviewKeyDownEvent PreviewKeyDownEvent PreviewKeyDownEvent PreviewKeyDownEvent

Identifica el evento adjunto PreviewKeyDown.Identifies the PreviewKeyDown attached event.

PreviewKeyUpEvent PreviewKeyUpEvent PreviewKeyUpEvent PreviewKeyUpEvent

Identifica el evento adjunto PreviewKeyUp.Identifies the PreviewKeyUp attached event.

PreviewLostKeyboardFocusEvent PreviewLostKeyboardFocusEvent PreviewLostKeyboardFocusEvent PreviewLostKeyboardFocusEvent

Identifica el evento adjunto PreviewLostKeyboardFocus.Identifies the PreviewLostKeyboardFocus attached event.

Propiedades

DefaultRestoreFocusMode DefaultRestoreFocusMode DefaultRestoreFocusMode DefaultRestoreFocusMode

Obtiene o establece el comportamiento de Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) cuando se restaura el foco.Gets or sets the behavior of Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) when restoring focus.

FocusedElement FocusedElement FocusedElement FocusedElement

Obtiene el elemento que tiene el foco de teclado.Gets the element that has keyboard focus.

Modifiers Modifiers Modifiers Modifiers

Obtiene el conjunto de ModifierKeys que se presionan actualmente.Gets the set of ModifierKeys that are currently pressed.

PrimaryDevice PrimaryDevice PrimaryDevice PrimaryDevice

Obtiene el dispositivo de entradas de teclado primario.Gets the primary keyboard input device.

Métodos

AddGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) AddGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) AddGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) AddGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler)

Agrega un controlador para el evento adjunto GotKeyboardFocus.Adds a handler for the GotKeyboardFocus attached event.

AddKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler) AddKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler) AddKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler) AddKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler)

Agrega un controlador para el evento adjunto KeyboardInputProviderAcquireFocus.Adds a handler for the KeyboardInputProviderAcquireFocus attached event.

AddKeyDownHandler(DependencyObject, KeyEventHandler) AddKeyDownHandler(DependencyObject, KeyEventHandler) AddKeyDownHandler(DependencyObject, KeyEventHandler) AddKeyDownHandler(DependencyObject, KeyEventHandler)

Agrega un controlador para el evento adjunto KeyDown.Adds a handler for the KeyDown attached event.

AddKeyUpHandler(DependencyObject, KeyEventHandler) AddKeyUpHandler(DependencyObject, KeyEventHandler) AddKeyUpHandler(DependencyObject, KeyEventHandler) AddKeyUpHandler(DependencyObject, KeyEventHandler)

Agrega un controlador para el evento adjunto KeyUp.Adds a handler for the KeyUp attached event.

AddLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) AddLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) AddLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) AddLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler)

Agrega un controlador para el evento adjunto LostKeyboardFocus.Adds a handler for the LostKeyboardFocus attached event.

AddPreviewGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) AddPreviewGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) AddPreviewGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) AddPreviewGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler)

Agrega un controlador para el evento adjunto PreviewGotKeyboardFocus.Adds a handler for the PreviewGotKeyboardFocus attached event.

AddPreviewKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler) AddPreviewKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler) AddPreviewKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler) AddPreviewKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler)

Agrega un controlador para el evento adjunto PreviewKeyboardInputProviderAcquireFocus.Adds a handler for the PreviewKeyboardInputProviderAcquireFocus attached event.

AddPreviewKeyDownHandler(DependencyObject, KeyEventHandler) AddPreviewKeyDownHandler(DependencyObject, KeyEventHandler) AddPreviewKeyDownHandler(DependencyObject, KeyEventHandler) AddPreviewKeyDownHandler(DependencyObject, KeyEventHandler)

Agrega un controlador para el evento adjunto PreviewKeyDown.Adds a handler for the PreviewKeyDown attached event.

AddPreviewKeyUpHandler(DependencyObject, KeyEventHandler) AddPreviewKeyUpHandler(DependencyObject, KeyEventHandler) AddPreviewKeyUpHandler(DependencyObject, KeyEventHandler) AddPreviewKeyUpHandler(DependencyObject, KeyEventHandler)

Agrega un controlador para el evento adjunto PreviewKeyUp.Adds a handler for the PreviewKeyUp attached event.

AddPreviewLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) AddPreviewLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) AddPreviewLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) AddPreviewLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler)

Agrega un controlador para el evento adjunto PreviewLostKeyboardFocus.Adds a handler for the PreviewLostKeyboardFocus attached event.

ClearFocus() ClearFocus() ClearFocus() ClearFocus()

Borra el foco.Clears focus.

Focus(IInputElement) Focus(IInputElement) Focus(IInputElement) Focus(IInputElement)

Establece el foco de teclado en el elemento especificado.Sets keyboard focus on the specified element.

GetKeyStates(Key) GetKeyStates(Key) GetKeyStates(Key) GetKeyStates(Key)

Obtiene el conjunto de estados de la tecla especificada.Gets the set of key states for the specified key.

IsKeyDown(Key) IsKeyDown(Key) IsKeyDown(Key) IsKeyDown(Key)

Determina si está presionada la tecla especificada.Determines whether the specified key is pressed.

IsKeyToggled(Key) IsKeyToggled(Key) IsKeyToggled(Key) IsKeyToggled(Key)

Determina la tecla especificada está en estado de alternancia.Determines whether the specified key is toggled.

IsKeyUp(Key) IsKeyUp(Key) IsKeyUp(Key) IsKeyUp(Key)

Determina si la tecla especificada está sin presionar.Determines whether the specified key is released.

RemoveGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) RemoveGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) RemoveGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) RemoveGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler)

Quita un controlador del evento adjunto GotKeyboardFocus.Removes a handler for the GotKeyboardFocus attached event.

RemoveKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler) RemoveKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler) RemoveKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler) RemoveKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler)

Quita un controlador del evento adjunto KeyboardInputProviderAcquireFocus.Removes a handler for the KeyboardInputProviderAcquireFocus attached event.

RemoveKeyDownHandler(DependencyObject, KeyEventHandler) RemoveKeyDownHandler(DependencyObject, KeyEventHandler) RemoveKeyDownHandler(DependencyObject, KeyEventHandler) RemoveKeyDownHandler(DependencyObject, KeyEventHandler)

Quita un controlador del evento adjunto KeyDown.Removes a handler for the KeyDown attached event.

RemoveKeyUpHandler(DependencyObject, KeyEventHandler) RemoveKeyUpHandler(DependencyObject, KeyEventHandler) RemoveKeyUpHandler(DependencyObject, KeyEventHandler) RemoveKeyUpHandler(DependencyObject, KeyEventHandler)

Quita un controlador del evento adjunto KeyUp.Removes a handler for the KeyUp attached event.

RemoveLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) RemoveLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) RemoveLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) RemoveLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler)

Quita un controlador del evento adjunto LostKeyboardFocus.Removes a handler for the LostKeyboardFocus attached event.

RemovePreviewGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) RemovePreviewGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) RemovePreviewGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) RemovePreviewGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler)

Quita un controlador del evento adjunto PreviewGotKeyboardFocus.Removes a handler for the PreviewGotKeyboardFocus attached event.

RemovePreviewKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler) RemovePreviewKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler) RemovePreviewKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler) RemovePreviewKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler)

Quita un controlador del evento adjunto PreviewKeyboardInputProviderAcquireFocus.Removes a handler for the PreviewKeyboardInputProviderAcquireFocus attached event.

RemovePreviewKeyDownHandler(DependencyObject, KeyEventHandler) RemovePreviewKeyDownHandler(DependencyObject, KeyEventHandler) RemovePreviewKeyDownHandler(DependencyObject, KeyEventHandler) RemovePreviewKeyDownHandler(DependencyObject, KeyEventHandler)

Quita un controlador del evento adjunto PreviewKeyDown.Removes a handler for the PreviewKeyDown attached event.

RemovePreviewKeyUpHandler(DependencyObject, KeyEventHandler) RemovePreviewKeyUpHandler(DependencyObject, KeyEventHandler) RemovePreviewKeyUpHandler(DependencyObject, KeyEventHandler) RemovePreviewKeyUpHandler(DependencyObject, KeyEventHandler)

Quita un controlador del evento adjunto PreviewKeyUp.Removes a handler for the PreviewKeyUp attached event.

RemovePreviewLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) RemovePreviewLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) RemovePreviewLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler) RemovePreviewLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler)

Quita un controlador del evento adjunto PreviewLostKeyboardFocus.Removes a handler for the PreviewLostKeyboardFocus attached event.

Eventos adjuntos

GotKeyboardFocus GotKeyboardFocus GotKeyboardFocus GotKeyboardFocus

Se produce cuando un elemento recibe el foco de teclado.Occurs when an element receives keyboard focus.

KeyboardInputProviderAcquireFocus KeyboardInputProviderAcquireFocus KeyboardInputProviderAcquireFocus KeyboardInputProviderAcquireFocus

Se produce cuando el proveedor de la acción del teclado adquiere el foco.Occurs when the keyboard input provider acquires focus.

KeyDown KeyDown KeyDown KeyDown

Se produce cuando se presiona una tecla en el teclado.Occurs when a key on the keyboard is pressed.

KeyUp KeyUp KeyUp KeyUp

Se produce cuando se suelta una tecla del teclado.Occurs when a key on the keyboard is released.

LostKeyboardFocus LostKeyboardFocus LostKeyboardFocus LostKeyboardFocus

Se produce cuando un elemento pierde el foco de teclado.Occurs when an element loses keyboard focus.

PreviewGotKeyboardFocus PreviewGotKeyboardFocus PreviewGotKeyboardFocus PreviewGotKeyboardFocus

Se produce cuando un elemento está adquiriendo el foco de teclado.Occurs when an element is in the process of acquiring keyboard focus.

PreviewKeyboardInputProviderAcquireFocus PreviewKeyboardInputProviderAcquireFocus PreviewKeyboardInputProviderAcquireFocus PreviewKeyboardInputProviderAcquireFocus

Se produce cuando el proveedor de la acción del teclado está adquiriendo el foco.Occurs when the keyboard input provider is in the process of acquiring focus.

PreviewKeyDown PreviewKeyDown PreviewKeyDown PreviewKeyDown

Se produce cuando se presiona una tecla en el teclado.Occurs when a key on the keyboard is pressed.

PreviewKeyUp PreviewKeyUp PreviewKeyUp PreviewKeyUp

Se produce cuando se suelta una tecla del teclado.Occurs when a key on the keyboard is released.

PreviewLostKeyboardFocus PreviewLostKeyboardFocus PreviewLostKeyboardFocus PreviewLostKeyboardFocus

Se produce cuando un elemento está perdiendo el foco de teclado.Occurs when an element is in the process of losing keyboard focus.

Se aplica a

Consulte también: