# InputManager::ProcessKeyDown 向输入系统注入一个按键按下事件。 ```cpp void ProcessKeyDown(KeyCode key, bool repeat, bool alt, bool ctrl, bool shift, bool meta); ``` ## 行为说明 当前实现会: - 如果未初始化或键索引越界,直接返回 - 把 `m_keyDown[index]` 设为 `true` - 把 `m_keyDownThisFrame[index]` 设为 `true` - 构造 `KeyEvent` - 如果 `repeat` 为 `true`,事件类型设为 `Repeat`,否则为 `Down` - 同步触发 `m_onKeyEvent` 这里有一个很重要的当前实现细节:`repeat` 只会影响事件类型,不会阻止本帧按下缓存被写入。也就是说,只要平台层再次调用 `ProcessKeyDown()`: - [IsKeyPressed](IsKeyPressed.md) 可能在该帧再次返回 `true` - [GetButtonDown](GetButtonDown.md) 可能再次返回 `true` - [IsAnyKeyPressed](IsAnyKeyPressed.md) 也可能再次成立 如果你需要“严格只响应首次物理按下”,需要结合 `repeat` 自己做过滤,或者在更上层维护去抖逻辑。 ## 参数 - `key` - 键值。 - `repeat` - 是否为重复按键事件。 - `alt` - Alt 修饰键状态。 - `ctrl` - Ctrl 修饰键状态。 - `shift` - Shift 修饰键状态。 - `meta` - Meta 修饰键状态。 ## 返回值 - 无。 ## 相关文档 - [返回类型总览](InputManager.md) - [OnKeyEvent](OnKeyEvent.md) - [ProcessKeyUp](ProcessKeyUp.md) - [IsKeyPressed](IsKeyPressed.md) - [GetButtonDown](GetButtonDown.md)