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

# XGameUiTextEntryOpen

> XGameUiTextEntryOpen

# XGameUiTextEntryOpen

タイトルがテキストのレンダリングを担当する仮想キーボードを開きます。デスクトップ上では現在
未実装です。

## Syntax

```cpp theme={null}
HRESULT XGameUiTextEntryOpen(  
         const XGameUiTextEntryOption* options,
         uint32_t maxLength,
         const char* initialText,
         uint32_t initialCursorIndex,
         XGameUiTextEntryHandle* handle 
)  
```

### Parameters

*options*   \_In\_\
型: [XGameUiTextEntryOptions](/reference/system/xgameui/structs/xgameuitextentryoptions)

キーボードを開くときに適用する初期オプション (配置やキーボード構成など) の
セットを示します。

*maxLength*   \_In\_\
型: uint32\_t

ユーザーが仮想キーボードで入力できる最大文字数。この数は 32K を超えることは
できません。

*initialText*   \_In\_\_opt\_z\_\
型: const char\*

仮想キーボードに最初に表示される null 終端の文字列。

*initialCursorIndex*   \_In\_\
型: uint32\_t

先頭文字を基準としたカーソルの初期バイト インデックス。

*handle*   \_Out\_\
型: XGameUiTextEntryHandle

新しく開いた仮想キーボードへのハンドル。

### Return value

型: HRESULT

HRESULT の成功またはエラー コード。エラー コードの一覧については、[Error Codes](/reference/errorcodes) を参照してください。

| 戻り値             | 説明                 |
| --------------- | ------------------ |
| S\_OK           | 操作が成功しました。         |
| E\_ACCESSDENIED | ダイアログがすでに表示されています。 |

## Remarks

この関数は、仮想キーボードがまだ表示されていない場合でも、ハンドルを取得でき次第すぐに返ります。
その他のすべての **XGameUiTextEntry** 関数は、ハンドルが返されたらすぐに安全に呼び出せます。

次の例は、**XGameUiTextEntry** 関数を使用する基本的な方法を示しています。

```cpp theme={null}
// Somewhere in the main game loop
// ...
bool someSignal;
bool showingKeyboard;
uint32_t KEYBOARD_MAX_CHARACTERS = 256; 
uint32_t KEYBOARD_BUFFER_SIZE = KEYBOARD_MAX_CHARACTERS * 4;

XGameUiTextEntryHandle keyboardInstance;

if (someSignal)
{
    XGameUiTextEntryOptions options;
    options.inputScope = XGameUiTextEntryInputScope::Default;
    options.positionHint = XGameUiTextEntryPositionHint::Bottom;
    options.flags = XGameUiTextEntryVisibilityFlags::Default;

    if (SUCCEEDED(XGameUiTextEntryOpen(&options, 
                                       nullptr, 
                                       0, 
                                       KEYBOARD_MAX_CHARACTERS, 
                                       &keyboardInstance)))
    {
        showingKeyboard = true;
    }
}

if (showingKeyboard)
{
    char* buffer[KEYBOARD_BUFFER_SIZE];
    uint32_t cursorPosition;
    XGameUiTextEntryChangeTypeFlags changeType;

    if (SUCCEEDED(XGameUiTextEntryGetState(
        keyboardInstance,
        &changeType,
        &cursorPosition,
        nullptr,
        nullptr,
        KEYBOARD_BUFFER_SIZE,
        buffer)))
    {
        if (changeType & XGameUiTextEntryChangeTypeFlags::TextChanged)
        {
            // Copy text for in-game rendering
            RenderTextInGame(buffer, cursorPosition);

            // Assuming the game doesn't want multi-line input
            if (strstr(buffer, "\n")
            {
                XGameUiTextEntryClose(keyboardInstance);
                showingKeyboard = false;
            }
        }

        if (showingKeyboard && (changeType & XGameUiTextEntryChangeTypeFlags::KeyboardDismissed))
        {
            XGameUiTextEntryClose(keyboardInstance);
            showingKeyboard = false;
        }    
    }
}
```

## Requirements

**ヘッダー:** XGameUI.h

**ライブラリ:** xgameruntime.lib

**サポートされているプラットフォーム:** Windows、XBOX One ファミリー本体および XBOX Series 本体

## See also

[XGameUI](/reference/system/xgameui/xgameui_members)\
[仮想キーボードのサポート](/build/core-features/common/input/overviews/virtualkeyboardsupport)


## Related topics

- [XGameUiTextEntryOptions](/ja-jp/reference/system/xgameui/structs/xgameuitextentryoptions.md)
- [XGameUiTextEntryClose](/ja-jp/reference/system/xgameui/functions/xgameuitextentryclose.md)
- [XGameUiTextEntryGetState](/ja-jp/reference/system/xgameui/functions/xgameuitextentrygetstate.md)
- [XGameUiTextEntryInputScope](/ja-jp/reference/system/xgameui/enums/xgameuitextentryinputscope.md)
- [仮想キーボードのサポート](/ja-jp/build/core-features/common/input/overviews/virtualkeyboardsupport.md)
