> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XINPUT_KEYSTROKE

> XINPUT_KEYSTROKE

# XINPUT\_KEYSTROKE

描述 XInputGetKeystroke 函式傳回的按鍵輸入資料。

<a id="syntaxSection" />

## 語法

```cpp theme={null}
typedef struct XINPUT_KEYSTROKE {  
    WORD VirtualKey;  
    WCHAR Unicode;  
    WORD Flags;  
    BYTE UserIndex;  
    BYTE HidCode;  
} XINPUT_KEYSTROKE  
```

<a id="membersSection" />

### 成員

*VirtualKey*\
類型：WORD

按鍵、按鈕或搖桿移動的虛擬按鍵碼。

*Unicode*\
類型：WCHAR

未使用此成員，其值為零。

*Flags*\
類型：WORD

指出輸入事件發生時鍵盤狀態的旗標。此成員可以是下列旗標的任意組合：

| 值 | 描述 |
| - | - |
| XINPUT\_KEYSTROKE\_KEYDOWN | 按鍵已按下。 |
| XINPUT\_KEYSTROKE\_KEYUP | 按鍵已放開。 |
| XINPUT\_KEYSTROKE\_REPEAT | 按住按鍵時的重複輸入。 |

*UserIndex*\
類型：BYTE

與耳機相關聯之玩家的索引；值的範圍為 0 到 `XUSER_MAX_COUNT - 1`。

*HidCode*\
類型：BYTE

對應至輸入的人性化介面裝置 (HID) 代碼。如果沒有對應的 HID 代碼，此值為零。

<a id="remarksSection" />

## 備註

此結構由 [XInputGetKeystroke](/zh-TW/reference/input/xinputongameinput/functions/xinputgetkeystroke) 函式使用。

未來的裝置可能會傳回目前裝置不支援且目前尚未定義的 HID 代碼和虛擬按鍵值。應用程式應忽略這些非預期的值。

虛擬按鍵碼是一個位元組值，代表鍵盤上特定的實體按鍵，而不是該按鍵根據鍵盤狀態可對應的一或多個字元 (可能沒有)。按下虛擬按鍵時的鍵盤狀態會修改所回報的字元。例如，`VK_4` 可能代表 "4" 或 "\$"，取決於 Shift 鍵的狀態。

回報的鍵盤事件包括造成事件的虛擬按鍵、按鍵是按下或放開 (或正在重複)，以及事件發生時的鍵盤狀態。鍵盤狀態會指出是否按下任何 Ctrl、Alt 或 Shift 鍵。

有效的虛擬按鍵碼 (VK\_xxx) 定義於 XInput.h 中。除了表示按鍵按下的代碼之外，下列代碼表示控制器輸入：

| 值 | 描述 |
| - | - |
| VK\_PAD\_A | **A** 按鈕 |
| VK\_PAD\_B | **B** 按鈕 |
| VK\_PAD\_X | **X** 按鈕 |
| VK\_PAD\_Y | **Y** 按鈕 |
| VK\_PAD\_RSHOULDER | 右肩按鈕 |
| VK\_PAD\_LSHOULDER | 左肩按鈕 |
| VK\_PAD\_LTRIGGER | 左扳機 |
| VK\_PAD\_RTRIGGER | 右扳機 |
| VK\_PAD\_DPAD\_UP | 方向鍵上 |
| VK\_PAD\_DPAD\_DOWN | 方向鍵下 |
| VK\_PAD\_DPAD\_LEFT | 方向鍵左 |
| VK\_PAD\_DPAD\_RIGHT | 方向鍵右 |
| VK\_PAD\_START | Start 按鈕 |
| VK\_PAD\_BACK | Back 按鈕 |
| VK\_PAD\_LTHUMB\_PRESS | 按下左搖桿 |
| VK\_PAD\_RTHUMB\_PRESS | 按下右搖桿 |
| VK\_PAD\_LTHUMB\_UP | 左搖桿向上 |
| VK\_PAD\_LTHUMB\_DOWN | 左搖桿向下 |
| VK\_PAD\_LTHUMB\_RIGHT | 左搖桿向右 |
| VK\_PAD\_LTHUMB\_LEFT | 左搖桿向左 |
| VK\_PAD\_LTHUMB\_UPLEFT | 左搖桿向左上 |
| VK\_PAD\_LTHUMB\_UPRIGHT | 左搖桿向右上 |
| VK\_PAD\_LTHUMB\_DOWNRIGHT | 左搖桿向右下 |
| VK\_PAD\_LTHUMB\_DOWNLEFT | 左搖桿向左下 |
| VK\_PAD\_RTHUMB\_UP | 右搖桿向上 |
| VK\_PAD\_RTHUMB\_DOWN | 右搖桿向下 |
| VK\_PAD\_RTHUMB\_RIGHT | 右搖桿向右 |
| VK\_PAD\_RTHUMB\_LEFT | 右搖桿向左 |
| VK\_PAD\_RTHUMB\_UPLEFT | 右搖桿向左上 |
| VK\_PAD\_RTHUMB\_UPRIGHT | 右搖桿向右上 |
| VK\_PAD\_RTHUMB\_DOWNRIGHT | 右搖桿向右下 |
| VK\_PAD\_RTHUMB\_DOWNLEFT | 右搖桿向左下 |

如需詳細資訊，請參閱 [XInputOnGameInput 包裝函式](/zh-TW/build/core-features/common/input/porting/input-porting-xinput#xinputWrapperSection)。

<a id="requirementsSection" />

## 需求

**標頭：** XInputOnGameInput.h

**支援的平台：** XBOX One 系列主機和 XBOX Series 主機

<a id="seealsoSection" />

## 另請參閱

[從 XInput 移植到 GameInput](/zh-TW/build/core-features/common/input/porting/input-porting-xinput)\
[XInputOnGameInput](/zh-TW/reference/input/xinputongameinput/xinputongameinput_members)


## Related topics

- [XInputGetKeystroke](/zh-TW/reference/input/xinputongameinput/functions/xinputgetkeystroke.md)
- [XInputOnGameInput](/zh-TW/reference/input/xinputongameinput/xinputongameinput_members.md)
- [從 XInput 移植到 GameInput](/zh-TW/build/core-features/common/input/porting/input-porting-xinput.md)
- [XINPUT_GAMEPAD](/zh-TW/reference/input/xinputongameinput/structs/xinput_gamepad.md)
- [XINPUT_CAPABILITIES](/zh-TW/reference/input/xinputongameinput/structs/xinput_capabilities.md)
