Files
XCEngine/docs/api/XCEngine/Input/InputManager/GetButtonDown.md

45 lines
1.1 KiB
Markdown
Raw Normal View History

2026-03-26 16:45:24 +08:00
# InputManager::GetButtonDown
2026-03-26 17:39:53 +08:00
查询一个具名逻辑按钮是否在本帧刚被按下。
2026-03-26 16:45:24 +08:00
```cpp
bool GetButtonDown(const Containers::String& buttonName) const;
```
2026-03-26 17:39:53 +08:00
## 行为说明
2026-03-26 16:45:24 +08:00
2026-04-08 16:07:03 +08:00
当前实现把逻辑按钮当作 `KeyCode` 别名处理,这个方法的工作流程是:
2026-03-26 16:45:24 +08:00
2026-04-08 16:07:03 +08:00
1.`m_buttons` 中查找 `buttonName`
2. 如果未注册,返回 `false`
3. 如果找到,则对映射后的键调用 [IsKeyPressed](IsKeyPressed.md)
这意味着它继承了 `IsKeyPressed()` 的全部语义:
- 返回的是“本帧按下边沿”,不是持续按住态
- 依赖 [Update](Update.md) 的帧边界
- 当前不会过滤平台重复按键消息;如果映射键在后续帧收到 repeat keydown本方法也可能再次返回 `true`
2026-03-26 16:45:24 +08:00
2026-03-26 17:39:53 +08:00
## 参数
2026-03-26 16:45:24 +08:00
2026-03-26 17:39:53 +08:00
- `buttonName` - 逻辑按钮名称。
## 返回值
- `bool` - 该按钮是否在本帧刚被按下。
2026-03-26 16:45:24 +08:00
2026-03-26 17:39:53 +08:00
## 示例
```cpp
if (XCEngine::Input::InputManager::Get().GetButtonDown("Fire1")) {
// ...
2026-03-26 16:45:24 +08:00
}
```
## 相关文档
2026-03-26 17:39:53 +08:00
- [返回类型总览](InputManager.md)
- [GetButton](GetButton.md)
- [GetButtonUp](GetButtonUp.md)
2026-04-08 16:07:03 +08:00
- [IsKeyPressed](IsKeyPressed.md)