Issue with ImmNotifyIME Returning False in Unity: Unable to Clear IME Composition

Anonymous
2024-11-27T10:54:54+00:00

Hello,

I am currently attempting to programmatically clear the IME composition string from a Unity C# script using Windows API calls. However, I am encountering an issue where the ImmNotifyIME function returns False, and the IME composition string and candidate window remain visible on the screen.

Problem Details:

  • Function Used: I am using ImmNotifyIME to try to close the IME composition string and candidate window.
  • Issue: The function returns False, but when I retrieve the error code using Marshal.GetLastWin32Error(), it returns 0 (ERROR_SUCCESS), indicating that no specific error has occurred.
  • Impact: Internally, it appears that the composition string is cleared, but visually, the composition string and candidate window remain displayed.
  • Reproducibility: The same behavior occurs with both Microsoft IME and Google Japanese Input.

Error Messages and Logs:

var result = ImmNotifyIME(hIMC, NI_CLOSECANDIDATE, 0, 0);
if (!result)
{
    int errorCode = Marshal.GetLastWin32Error();
    Debug.LogError($"ImmNotifyIME failed with error code: {errorCode}");
}
  • Error Code Output: 0

System Information:

  • Unity Version: 2022.3.28f1
  • IME Used: Microsoft IME for Japanese Input

What I've Tried:

private const int NI_COMPOSITIONSTR = 0x15;
    private const int NI_CLOSECANDIDATE = 0x0010;
    private const int CPS_CANCEL = 0x4;
    private const int CPS_COMPLETE = 0x1;
    private const uint SCS_SETSTR = 0x0009;

IntPtr hIMC = ImmGetContext(windowHandle);
        if (hIMC != IntPtr.Zero)
        {
            //The text in InputField does not disappear here.
            ImmNotifyIME(hIMC, NI_CLOSECANDIDATE, 0, 0);

            ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_COMPLETE, 0);

            ImmSetCompositionString(hIMC, SCS_SETSTR, IntPtr.Zero, 0, IntPtr.Zero, 0);

            ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_CANCEL, 0);

            ImmReleaseContext(windowHandle, hIMC);
        }

Questions:

  • What could be the possible reasons for ImmNotifyIME returning False with an error code of 0?
  • Is there a reliable way to programmatically clear the IME composition string and candidate window?
  • Are there other functions or approaches I should try?

I would greatly appreciate any guidance or suggestions.

Thank you.

ビジネス向け Windows | IT プロフェッショナル用 Windows クライアント | パフォーマンス | アプリケーション テクノロジと互換性

ロックされた質問。 この質問は、Microsoft サポート コミュニティから移行されました。 役に立つかどうかに投票することはできますが、コメントの追加、質問への返信やフォローはできません。

0 件のコメント コメントはありません

1 件の回答

並べ替え方法: 新しい順
  1. Anonymous
    2024-11-27T23:49:24+00:00

    この応答は自動的に翻訳されています。 その結果、文法上の誤りや奇妙な言い回しが生じる可能性があります。

    こんにちは 

    マイクロソフト コミュニティ フォーラムに投稿していただき、ありがとうございます。

    説明に基づいて、あなたの質問はUnityに関連していることを理解しています。

    このフォーラムにはこのトピックを専門とするエンジニアがいないため、問題を迅速かつ効果的に処理できるようにするために、Stack OverflowまたはMicrosoft Q&Aに質問を再投稿することをお勧めします。

    ご理解とご支援を賜りますようお願い申し上げます。ご不明な点やご不明な点がございましたら、お気軽にお知らせください。

    よい一日を!

    よろしくお願いいたします

    ウェスリー・リー

    この回答は役に立ちましたか?

    0 件のコメント コメントはありません