Keyboard Clase

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
Keyboard

Ejemplos

En el ejemplo siguiente se muestra cómo utilizar el método IsKeyToggled 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 alterna el Key pasado a IsKeyToggled, 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 clase Keyboard 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 que Keyboard define como un evento adjunto también se vuelve a exponer mediante las clases de elementos base UIElement y ContentElement 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 aplicación en UIElement y ContentElement, en lugar de usar los eventos Keyboard.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 mayoría de los objetos derivados de UIElement 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 foco, establezca la propiedad Focusable del elemento base en true.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.

Panel clases, como StackPanel y Canvas, establezca 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 el foco de teclado, Focusable debe establecerse en true.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 teclado ha IsKeyboardFocused establecido en true.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 la clase Keyboard delegan en el KeyboardDevice principal del subproceso que realiza la llamada, por lo que no son necesariamente 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

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

KeyboardInputProviderAcquireFocusEvent

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

KeyDownEvent

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

KeyUpEvent

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

LostKeyboardFocusEvent

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

PreviewGotKeyboardFocusEvent

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

PreviewKeyboardInputProviderAcquireFocusEvent

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

PreviewKeyDownEvent

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

PreviewKeyUpEvent

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

PreviewLostKeyboardFocusEvent

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

Propiedades

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

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

Modifiers

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

PrimaryDevice

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

Métodos

AddGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler)

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

AddKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler)

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

AddKeyDownHandler(DependencyObject, KeyEventHandler)

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

AddKeyUpHandler(DependencyObject, KeyEventHandler)

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

AddLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler)

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

AddPreviewGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler)

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

AddPreviewKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler)

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

AddPreviewKeyDownHandler(DependencyObject, KeyEventHandler)

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

AddPreviewKeyUpHandler(DependencyObject, KeyEventHandler)

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

AddPreviewLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler)

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

ClearFocus()

Borra el foco.Clears focus.

Focus(IInputElement)

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

GetKeyStates(Key)

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

IsKeyDown(Key)

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

IsKeyToggled(Key)

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

IsKeyUp(Key)

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

RemoveGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler)

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

RemoveKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler)

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

RemoveKeyDownHandler(DependencyObject, KeyEventHandler)

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

RemoveKeyUpHandler(DependencyObject, KeyEventHandler)

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

RemoveLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler)

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

RemovePreviewGotKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler)

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

RemovePreviewKeyboardInputProviderAcquireFocusHandler(DependencyObject, KeyboardInputProviderAcquireFocusEventHandler)

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

RemovePreviewKeyDownHandler(DependencyObject, KeyEventHandler)

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

RemovePreviewKeyUpHandler(DependencyObject, KeyEventHandler)

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

RemovePreviewLostKeyboardFocusHandler(DependencyObject, KeyboardFocusChangedEventHandler)

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

Eventos adjuntos

GotKeyboardFocus

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

KeyboardInputProviderAcquireFocus

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

KeyDown

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

KeyUp

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

LostKeyboardFocus

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

PreviewGotKeyboardFocus

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

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

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

PreviewKeyUp

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

PreviewLostKeyboardFocus

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

Se aplica a

Consulte también: