Keyboard Keyboard Keyboard Keyboard Class

定義

キーボード デバイスを表します。Represents the keyboard device.

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

次の例は、 IsKeyToggledメソッドを使用して、キーが切り替えられた状態かどうかを判断する方法を示しています。The following example shows how to use the IsKeyToggled method to determine if a key is in the toggled state. KeyIsKeyToggled渡されたが切り替えられると、ボタンの背景が変わります。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

注釈

クラスKeyboardには、キーボードの状態に関する情報を提供するキーボード関連のイベント、メソッド、およびプロパティが用意されています。The Keyboard class provides keyboard-related events, methods, and properties that provide information regarding the state of the keyboard.

を添付イベントとしKeyboardて定義する各イベントは、基本要素クラスUIElementおよびContentElement新しいルーティングイベントによっても再公開されます。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. 一般に、 UIElement Keyboardイベントを使用するのではなく、とContentElementでアプリケーションのキーボードイベントを処理する方が便利です。Generally, it is more convenient to handle keyboard events for an application on UIElement and ContentElement, rather than using the Keyboard events. 詳細については、「入力の概要」を参照してください。For details, see Input Overview.

要素がキーボード入力を受け取るには、要素にフォーカスを設定する必要があります。In order for an element to receive keyboard input, the element must be focusable. 既定UIElementでは、ほとんどの派生オブジェクトはフォーカスを設定できます。Most UIElement derived objects are focusable by default. それ以外の場合は、要素にフォーカスをFocusable設定するには、基本true要素のプロパティをに設定します。Otherwise, to make an element focusable, set the Focusable property on the base element to true. 基本要素の詳細については、「基本要素の概要」を参照してください。For more information on the base elements, see Base Elements Overview.

Panelクラス ( StackPanelCanvasなど) では、のFocusable既定値がfalseに設定されます。Panel classes, such as StackPanel and Canvas, set the default value of Focusable to false. そのため、これらのオブジェクトでキーボードフォーカスをFocusable取得するにはtrue、をに設定する必要があります。Therefore, for these objects to obtain keyboard focus, Focusable must be set to true.

キーボードフォーカスは、キーボード入力を受け取るオブジェクトを参照します。Keyboard focus refers to the object that is receiving keyboard input. キーボードフォーカスを持つ要素がIsKeyboardFocusedtrue設定されています。The element with keyboard focus has IsKeyboardFocused set to true. キーボードフォーカスを持つ要素は、デスクトップ全体に1つだけ存在できます。There can be only one element with keyboard focus on the entire desktop. 論理フォーカスとは、フォーカスがあるフォーカススコープ内のオブジェクトを指します。Logical focus refers to the object within a focus scope that has focus. フォーカス、キーボードフォーカス、および論理フォーカスの詳細については、「入力の概要」と「フォーカスの概要」を参照してください。For more information on focus, keyboard focus, and logical focus, see Input Overview and Focus Overview.

Keyboardクラスの静的メンバーは、呼び出し元のスレッドKeyboardDeviceのプライマリに委任されるため、必ずしもスレッドセーフであるとは限りません。The static members of the Keyboard class delegate to the primary KeyboardDevice of the calling thread, so they are not necessarily thread-safe.

フィールド

GotKeyboardFocusEvent GotKeyboardFocusEvent GotKeyboardFocusEvent GotKeyboardFocusEvent

GotKeyboardFocus 添付イベントを識別します。Identifies the GotKeyboardFocus attached event.

KeyboardInputProviderAcquireFocusEvent KeyboardInputProviderAcquireFocusEvent KeyboardInputProviderAcquireFocusEvent KeyboardInputProviderAcquireFocusEvent

KeyboardInputProviderAcquireFocus 添付イベントを識別します。Identifies the KeyboardInputProviderAcquireFocus attached event.

KeyDownEvent KeyDownEvent KeyDownEvent KeyDownEvent

KeyDown 添付イベントを識別します。Identifies the KeyDown attached event.

KeyUpEvent KeyUpEvent KeyUpEvent KeyUpEvent

KeyUp 添付イベントを識別します。Identifies the KeyUp attached event.

LostKeyboardFocusEvent LostKeyboardFocusEvent LostKeyboardFocusEvent LostKeyboardFocusEvent

LostKeyboardFocus 添付イベントを識別します。Identifies the LostKeyboardFocus attached event.

PreviewGotKeyboardFocusEvent PreviewGotKeyboardFocusEvent PreviewGotKeyboardFocusEvent PreviewGotKeyboardFocusEvent

PreviewGotKeyboardFocus 添付イベントを識別します。Identifies the PreviewGotKeyboardFocus attached event.

PreviewKeyboardInputProviderAcquireFocusEvent PreviewKeyboardInputProviderAcquireFocusEvent PreviewKeyboardInputProviderAcquireFocusEvent PreviewKeyboardInputProviderAcquireFocusEvent

PreviewKeyboardInputProviderAcquireFocus 添付イベントを識別します。Identifies the PreviewKeyboardInputProviderAcquireFocus attached event.

PreviewKeyDownEvent PreviewKeyDownEvent PreviewKeyDownEvent PreviewKeyDownEvent

PreviewKeyDown 添付イベントを識別します。Identifies the PreviewKeyDown attached event.

PreviewKeyUpEvent PreviewKeyUpEvent PreviewKeyUpEvent PreviewKeyUpEvent

PreviewKeyUp 添付イベントを識別します。Identifies the PreviewKeyUp attached event.

PreviewLostKeyboardFocusEvent PreviewLostKeyboardFocusEvent PreviewLostKeyboardFocusEvent PreviewLostKeyboardFocusEvent

PreviewLostKeyboardFocus 添付イベントを識別します。Identifies the PreviewLostKeyboardFocus attached event.

プロパティ

DefaultRestoreFocusMode DefaultRestoreFocusMode DefaultRestoreFocusMode DefaultRestoreFocusMode

フォーカスを復元するときの Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) の動作を取得または設定します。Gets or sets the behavior of Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) when restoring focus.

FocusedElement FocusedElement FocusedElement FocusedElement

キーボード フォーカスを持つ要素を取得します。Gets the element that has keyboard focus.

Modifiers Modifiers Modifiers Modifiers

現在押されている ModifierKeys のセットを取得します。Gets the set of ModifierKeys that are currently pressed.

PrimaryDevice PrimaryDevice PrimaryDevice PrimaryDevice

プライマリ キーボード入力デバイスを取得します。Gets the primary keyboard input device.

メソッド

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

GotKeyboardFocus 添付イベントのハンドラーを追加します。Adds a handler for the GotKeyboardFocus attached event.

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

KeyboardInputProviderAcquireFocus 添付イベントのハンドラーを追加します。Adds a handler for the KeyboardInputProviderAcquireFocus attached event.

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

KeyDown 添付イベントのハンドラーを追加します。Adds a handler for the KeyDown attached event.

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

KeyUp 添付イベントのハンドラーを追加します。Adds a handler for the KeyUp attached event.

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

LostKeyboardFocus 添付イベントのハンドラーを追加します。Adds a handler for the LostKeyboardFocus attached event.

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

PreviewGotKeyboardFocus 添付イベントのハンドラーを追加します。Adds a handler for the PreviewGotKeyboardFocus attached event.

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

PreviewKeyboardInputProviderAcquireFocus 添付イベントのハンドラーを追加します。Adds a handler for the PreviewKeyboardInputProviderAcquireFocus attached event.

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

PreviewKeyDown 添付イベントのハンドラーを追加します。Adds a handler for the PreviewKeyDown attached event.

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

PreviewKeyUp 添付イベントのハンドラーを追加します。Adds a handler for the PreviewKeyUp attached event.

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

PreviewLostKeyboardFocus 添付イベントのハンドラーを追加します。Adds a handler for the PreviewLostKeyboardFocus attached event.

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

フォーカスをクリアします。Clears focus.

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

指定した要素にキーボード フォーカスを設定します。Sets keyboard focus on the specified element.

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

指定したキーの状態のセットを取得します。Gets the set of key states for the specified key.

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

指定したキーが押されたかどうかを確認します。Determines whether the specified key is pressed.

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

指定したキーが切り替えられたかどうかを確認します。Determines whether the specified key is toggled.

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

指定したキーが離されたかどうかを確認します。Determines whether the specified key is released.

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

GotKeyboardFocus 添付イベントのハンドラーを削除します。Removes a handler for the GotKeyboardFocus attached event.

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

KeyboardInputProviderAcquireFocus 添付イベントのハンドラーを削除します。Removes a handler for the KeyboardInputProviderAcquireFocus attached event.

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

KeyDown 添付イベントのハンドラーを削除します。Removes a handler for the KeyDown attached event.

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

KeyUp 添付イベントのハンドラーを削除します。Removes a handler for the KeyUp attached event.

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

LostKeyboardFocus 添付イベントのハンドラーを削除します。Removes a handler for the LostKeyboardFocus attached event.

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

PreviewGotKeyboardFocus 添付イベントのハンドラーを削除します。Removes a handler for the PreviewGotKeyboardFocus attached event.

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

PreviewKeyboardInputProviderAcquireFocus 添付イベントのハンドラーを削除します。Removes a handler for the PreviewKeyboardInputProviderAcquireFocus attached event.

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

PreviewKeyDown 添付イベントのハンドラーを削除します。Removes a handler for the PreviewKeyDown attached event.

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

PreviewKeyUp 添付イベントのハンドラーを削除します。Removes a handler for the PreviewKeyUp attached event.

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

PreviewLostKeyboardFocus 添付イベントのハンドラーを削除します。Removes a handler for the PreviewLostKeyboardFocus attached event.

添付イベント

GotKeyboardFocus GotKeyboardFocus GotKeyboardFocus GotKeyboardFocus

要素がキーボード フォーカスを受け取ったときに発生します。Occurs when an element receives keyboard focus.

KeyboardInputProviderAcquireFocus KeyboardInputProviderAcquireFocus KeyboardInputProviderAcquireFocus KeyboardInputProviderAcquireFocus

キーボード入力プロバイダーがフォーカスを取得するときに発生します。Occurs when the keyboard input provider acquires focus.

KeyDown KeyDown KeyDown KeyDown

キーボードのキーが押されると発生します。Occurs when a key on the keyboard is pressed.

KeyUp KeyUp KeyUp KeyUp

キーボードのキーを離すと発生します。Occurs when a key on the keyboard is released.

LostKeyboardFocus LostKeyboardFocus LostKeyboardFocus LostKeyboardFocus

要素がキーボード フォーカスを失うと発生します。Occurs when an element loses keyboard focus.

PreviewGotKeyboardFocus PreviewGotKeyboardFocus PreviewGotKeyboardFocus PreviewGotKeyboardFocus

要素がキーボード フォーカスを取得中の場合に発生します。Occurs when an element is in the process of acquiring keyboard focus.

PreviewKeyboardInputProviderAcquireFocus PreviewKeyboardInputProviderAcquireFocus PreviewKeyboardInputProviderAcquireFocus PreviewKeyboardInputProviderAcquireFocus

キーボード入力プロバイダーがフォーカスを取得中の場合に発生します。Occurs when the keyboard input provider is in the process of acquiring focus.

PreviewKeyDown PreviewKeyDown PreviewKeyDown PreviewKeyDown

キーボードのキーが押されると発生します。Occurs when a key on the keyboard is pressed.

PreviewKeyUp PreviewKeyUp PreviewKeyUp PreviewKeyUp

キーボードのキーを離すと発生します。Occurs when a key on the keyboard is released.

PreviewLostKeyboardFocus PreviewLostKeyboardFocus PreviewLostKeyboardFocus PreviewLostKeyboardFocus

要素がキーボード フォーカスを喪失中の場合に発生します。Occurs when an element is in the process of losing keyboard focus.

適用対象

こちらもご覧ください