简体   繁体   中英

How to take Korean input in Winform?

I want to type Korean text in my ediatble area inside a winform application.

But Characters are repeating, I have tried to override the default WndProc , but nothing working.

switch (m.WParam.ToInt32())
                {
case Common.Interop.Window.WM_IME_CHAR:
                break;

            case Common.Interop.Window.WM_IME_ENDCOMPOSITION:
                    PassCharToScreen(m);
                break;

            case Common.Interop.Window.WM_CHAR:
                    PassCharToScreen(m);
                break;

            case Common.Interop.Window.WM_IME_NOTIFY:
                break;
            case Common.Interop.Window.WM_IME_COMPOSITION:
                PassCharToScreen(m);
                break;
            case Common.Interop.Window.WM_IME_COMPOSITIONFULL:
                break;

When I type in English, breakpoint hits WM_CHAR , But When I type in Korean it hits WM_IME_COMPOSITION on first character, and then after first character it hits WM_IME_COMPOSITION first and then hits WM_CHAR .

I have observed that it types first character correct. eg ㅁ (Korean Character) On typing second character. ㅁㅂㅁ (First char, second char, first char). I want the behaviour as it is in notepad

I have somehow solved the issue, I'm writing here to help others. Please let me know if there is any bug in the code.

private bool mIsImeProcessed = true;
private bool mIsImeContinue = false;

case WM_IME_COMPOSITION:
                {
                    if (mKoreanInput == true)
                    {
                        long lParam = m.LParam.ToInt64();
                        long wParam = m.WParam.ToInt64();
                        char c = (char)m.WParam;
                        if (lParam == 24600)
                        {
                            if (mIsImeProcessed)
                            {
                                mIsImeProcessed = false;
                                mIsImeContinue = false;
                                PassCharToThirdParty(m);
                            }
                            else
                            {
                                PassCharToThirdPartyWithBackSpace(((char)m.WParam).ToString());
                            }
                            mIsImeContinue = true;
                        }
                    }
                    else if (lParam == 2048)
                    {
                        if (mIsImeProcessed)
                        {
                        }
                        else
                        {
                            if (mIsImeContinue == true)
                            {

                                PassCharToThirdPartyWithBackSpace(((char)m.WParam).ToString());
                            }
                        }

                        mIsImeProcessed = true;

                    }
                    else
                    {
                            PassBackSpaceToThirdParty();
                    }
                }
                break;
case Common.Interop.Window.WM_IME_ENDCOMPOSITION:
                if (mKoreanInput == true)
                {
                    mIsImeProcessed = true;
                    mIsImeContinue = false;
                }
                break; 

First check whether language is Korean or other language, So if its Korean you have to handle it differently.

You have to get the info of Start and End composition and you have to always check whether its continuation of character or composition. Set mIsImeProcessed to true and mIsImeContinue to false once you get End of Composition in WndProc .

We need to handle case for backspace too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM