> ## 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.

# 虚拟键盘支持

> 虚拟键盘支持

在 PC 上，通常假定物理连接了键盘，但游戏手柄和触控等新的输入方式挑战了这一假定。这对于掌机和主机玩家尤为重要。根据平台不同，可通过不同方案调出虚拟键盘。虽然游戏可以自行实现和创建虚拟键盘，但系统提供了针对平台优化的虚拟键盘方案，可在所有游戏中提供一致的用户体验。

在 Windows 上，可以将 `TryShow` API 与新的 `CoreInputViewKind::Gamepad` 选项结合使用。然后使用 `TryHide` API 在不需要时关闭键盘。以下代码示例演示了这一点：

```C theme={null}
#include <winrt/windows.ui.viewmanagement.core.h>
using namespace winrt::Windows::UI::ViewManagement::Core;

// CoreInputViewKind::Gamepad enum requires headers from 26100.3624 Windows SDK or greater
// Otherwise, use static_cast<CoreInputViewKind>(7) for earlier SDKs

CoreInputView::GetForCurrentView().TryShow(CoreInputViewKind::Gamepad));

CoreInputView::GetForCurrentView().TryHide();
```

对于主机，GDK 提供了两种不同的方案来使用虚拟键盘处理文本输入。对于大多数游戏，最佳方案是使用 [XGameUiShowTextEntryAsync](/reference/system/xgameui/functions/xgameuishowtextentryasync)。对于需要渲染多行文本或输入超过 1024 个字符的游戏，可以使用 [XGameUiTextEntryOpen](/reference/system/xgameui/functions/xgameuitextentryopen)。

下表比较了这两种方案。

| 说明    | XGameUiShowTextEntryAsync | XGameUiTextEntryOpen |
| ----- | ------------------------- | -------------------- |
| 多行支持  | 否                         | 是                    |
| 最大字符数 | 1024                      | 1024 \* 32           |
| 输入焦点  | 虚拟键盘获得输入焦点                | 虚拟键盘获得输入焦点           |
| 定位    | 固定位置                      | 由游戏定位                |
| 文本渲染  | 由虚拟键盘处理                   | 由游戏处理                |
| 云串流行为 | 在客户端上使用虚拟键盘               | 由串流服务器渲染             |

## 另请参阅

[Windows 掌机设备上的 GDK 游戏清单 - 检查项 3：文本输入](/build/gdk-and-engines/handheld/handheld-guidance) [XGameUiShowTextEntryAsync](/reference/system/xgameui/functions/xgameuishowtextentryasync) [XGameUiTextEntryOpen](/reference/system/xgameui/functions/xgameuitextentryopen)


## Related topics

- [XGameUiTextEntryOpen](/zh-CN/reference/system/xgameui/functions/xgameuitextentryopen.md)
- [XGameUiShowTextEntryAsync](/zh-CN/reference/system/xgameui/functions/xgameuishowtextentryasync.md)
- [概述](/zh-CN/build/core-features/common/input/overviews/index.md)
- [输入](/zh-CN/build/core-features/common/input/gc-input-toc.md)
- [无障碍元数据](/zh-CN/publishing/game-publishing/concepts/metadata-accessibility.md)
