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

38 lines
692 B
Markdown
Raw Normal View History

2026-03-26 16:45:24 +08:00
# InputManager::GetButton
2026-03-26 17:39:53 +08:00
查询一个具名逻辑按钮当前是否按下。
2026-03-26 16:45:24 +08:00
```cpp
bool GetButton(const Containers::String& buttonName) const;
```
2026-03-26 17:39:53 +08:00
## 行为说明
2026-03-26 16:45:24 +08:00
2026-03-26 17:39:53 +08:00
当前逻辑按钮只是“名字到 `KeyCode`”的映射。这个方法会:
2026-03-26 16:45:24 +08:00
2026-03-26 17:39:53 +08:00
1. 查找 `buttonName`
2. 如果找到,则调用 `IsKeyDown(mappedKey)`
3. 如果没找到,则返回 `false`
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().GetButton("Jump")) {
// ...
2026-03-26 16:45:24 +08:00
}
```
## 相关文档
2026-03-26 17:39:53 +08:00
- [返回类型总览](InputManager.md)
- [GetButtonDown](GetButtonDown.md)
- [RegisterButton](RegisterButton.md)