0

このページに従って、コールバック (glfwSetCharCallback を使用して設定) を使用して GLFW からユーザー入力を読み取っています: http://www.glfw.org/docs/latest/input.html#input_char

コールバック関数は、押されたキーを 32 ビットの unsigned int として受け取ります。これを画面に印刷できるものに変換するにはどうすればよいですか? C++11 の codecvt と ICU ライブラリの両方を試しましたが、端末に読み取り可能な文字を出力するものは何もありませんでした。

これは私のコールバック関数のコードです:

void InputManager::charInputCallback(GLFWwindow* window, unsigned int key)
    {
        UErrorCode errorStatus = U_ZERO_ERROR; //initialize to no error
        UConverter *utf32toUnicode = ucnv_open("UTF-32", &errorStatus); //create converter utf-32 <=> Unicode
        if(U_FAILURE(errorStatus))
            std::cout << u_errorName(errorStatus) << std::endl;
        UChar unicode[10] = {0};
        ucnv_toUChars(utf32toUnicode, unicode, 10, (char*)key, 4, &errorStatus); // this fails with an U_ILLEGAL_ARGUMENT_ERROR
        if(U_FAILURE(errorStatus))
            std::cout << u_errorName(errorStatus) << std::endl;

        std::cout << unicode << std::endl;
    }

入力 (キー) に何もしないと、何も表示されません。ただの空白行。

4

1 に答える 1

0

8 ビット文字列を Unicode に変換する ucnv_toUChars() を呼び出しています。ただし、別の方法で、Unicode 文字列を UTF-8 などの 8 ビットに変換する必要があります。UTF-32 を受け取るコンストラクターと toUTF8String() メソッドを持つ UnicodeString クラスを使用します。

于 2016-09-07T21:38:24.707 に答える