> ## 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](/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 包装器](/build/core-features/common/input/porting/input-porting-xinput#xinputWrapperSection)。

<a id="requirementsSection" />

## 要求

**头文件：** XInputOnGameInput.h

**支持的平台：** XBOX One 系列主机和 XBOX Series 主机

<a id="seealsoSection" />

## 另请参阅

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


## Related topics

- [XInputGetKeystroke](/zh-CN/reference/input/xinputongameinput/functions/xinputgetkeystroke.md)
- [XInputOnGameInput](/zh-CN/reference/input/xinputongameinput/xinputongameinput_members.md)
- [从 XInput 移植到 GameInput](/zh-CN/build/core-features/common/input/porting/input-porting-xinput.md)
- [XINPUT_GAMEPAD](/zh-CN/reference/input/xinputongameinput/structs/xinput_gamepad.md)
- [XINPUT_VIBRATION](/zh-CN/reference/input/xinputongameinput/structs/xinput_vibration.md)
