在 PC 上,通常假定物理连接了键盘,但游戏手柄和触控等新的输入方式挑战了这一假定。这对于掌机和主机玩家尤为重要。根据平台不同,可通过不同方案调出虚拟键盘。虽然游戏可以自行实现和创建虚拟键盘,但系统提供了针对平台优化的虚拟键盘方案,可在所有游戏中提供一致的用户体验。在 Windows 上,可以将 TryShow API 与新的 CoreInputViewKind::Gamepad 选项结合使用。然后使用 TryHide API 在不需要时关闭键盘。以下代码示例演示了这一点:
#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 SDKsCoreInputView::GetForCurrentView().TryShow(CoreInputViewKind::Gamepad));CoreInputView::GetForCurrentView().TryHide();