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

47 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# InputManager::IsKeyUp
查询一个键当前是否处于抬起状态。
```cpp
bool IsKeyUp(KeyCode key) const;
```
## 行为说明
当前实现直接把它定义成“不是 Down”
- 如果管理器未初始化,返回 `true`
- 否则返回 `!IsKeyDown(key)`
- 如果 `KeyCode` 超出内部数组范围,`IsKeyDown()` 会返回 `false`,因此这里也会表现为 `true`
因此对于未初始化、越界或当前未按住的键,它都会被视为 “Up”。
这和 [IsKeyReleased](IsKeyReleased.md) 要区分开:
- `IsKeyUp()` 回答的是“现在有没有按住”
- `IsKeyReleased()` 回答的是“这一帧是否刚释放”
如果你要做“松开键就触发一次”这类逻辑,应优先使用释放边沿接口,而不是用 `IsKeyUp()` 轮询。
## 参数
- `key` - 要查询的键。
## 返回值
- `bool` - 当前是否抬起。
## 示例
```cpp
if (XCEngine::Input::InputManager::Get().IsKeyUp(XCEngine::Input::KeyCode::Space)) {
// Space 当前没有被按住
}
```
## 相关文档
- [返回类型总览](InputManager.md)
- [IsKeyDown](IsKeyDown.md)
- [IsKeyReleased](IsKeyReleased.md)