> ## 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 上，可以搭配新的 `CoreInputViewKind::Gamepad` 選項運用 `TryShow` API。然後可以使用 `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](/zh-TW/reference/system/xgameui/functions/xgameuishowtextentryasync)。對於需要轉譯多行文字或輸入超過 1024 個字元的遊戲，可以使用 [XGameUiTextEntryOpen](/zh-TW/reference/system/xgameui/functions/xgameuitextentryopen)。

下表提供這兩種解決方案的比較。

| 描述 | XGameUiShowTextEntryAsync | XGameUiTextEntryOpen |
| - | - | - |
| 多行支援 | 否 | 是 |
| 字元數上限 | 1024 | 1024 \* 32 |
| 輸入焦點 | 虛擬鍵盤取得輸入焦點 | 虛擬鍵盤取得輸入焦點 |
| 位置 | 固定位置 | 由遊戲決定位置 |
| 文字轉譯 | 由虛擬鍵盤處理 | 由遊戲處理 |
| 雲端串流行為 | 運用用戶端上的虛擬鍵盤 | 由串流伺服器轉譯 |

## 另請參閱

[Windows 掌上型裝置上 GDK 遊戲的檢查清單 - 檢查 3：文字輸入](/zh-TW/build/gdk-and-engines/handheld/handheld-guidance) [XGameUiShowTextEntryAsync](/zh-TW/reference/system/xgameui/functions/xgameuishowtextentryasync) [XGameUiTextEntryOpen](/zh-TW/reference/system/xgameui/functions/xgameuitextentryopen)


## Related topics

- [XBOX Accessibility Guidelines (XAG)](/zh-TW/build/game-principles/accessibility/xbox-accessibility-guidelines.md)
- [認證主機 BVT 指南](/zh-TW/publishing/game-publishing/concepts/certification/certification-console-bvt-guide.md)
- [認證逐步指南](/zh-TW/publishing/game-publishing/concepts/certification/certification-guide.md)
- [無障礙功能標籤](/zh-TW/build/game-principles/accessibility/accessibility-feature-tags.md)
- [Windows 與 ROG XBOX Ally 總覽](/zh-TW/paths/windows/overview.md)
