コード例 #1
0
    public void KeyDown(VirtualKey _key)
    {
        if (_key.KeyType != VirtualKey.kType.kReturn)
        {
            PlayKeyAudio();
        }


        if (TextInputBox != null)
        {
            switch (_key.KeyType)
            {
            case VirtualKey.kType.kShift:
            {
                mPressShift = !mPressShift;
            }
            break;

            case VirtualKey.kType.kCapsLock:
            {
                mCapsLocked = !mCapsLocked;
            }
            break;

            case VirtualKey.kType.kHangul:
            {
                if (mLanguage == kLanguage.kKorean)
                {
                    mLanguage = kLanguage.kEnglish;
                }
                else
                {
                    mLanguage = kLanguage.kKorean;
                }
            }
            break;

            case VirtualKey.kType.kSpace:
            {
                if (TextInputBox.TextField.Length <= MaxTextCount)
                {
                    TextInputBox.KeyDown(_key);
                }
            }
            break;

            case VirtualKey.kType.kBackspace:
            {
                TextInputBox.KeyDown(_key);
            }
            break;

            case VirtualKey.kType.kReturn:
            {
                if (OnReturnEventHandler != null)
                {
                    //OnReturnEventHandler(TextInputBox.TextField);
                }
                //do somehing
                //OnReturnEventHandler?.Invoke(TextInputBox.TextField);

                if ((bool)OnReturnDelegate?.Invoke(TextInputBox.TextField))
                {
                    PlayKeyAudio();
                }
            }
            break;

            case VirtualKey.kType.kCharacter:
            {
                if (TextInputBox.TextField.Length <= MaxTextCount)
                {
                    char keyCharacter = _key.KeyCharacter;
                    if (mPressShift)
                    {
                        keyCharacter = char.ToUpper(keyCharacter);
                        mPressShift  = false;
                    }

                    if (mLanguage == kLanguage.kKorean)
                    {
                        TextInputBox.KeyDownHangul(keyCharacter);
                    }
                    else if (mLanguage == kLanguage.kEnglish)
                    {
                        if (mCapsLocked)
                        {
                            keyCharacter = char.ToUpper(keyCharacter);
                        }
                        TextInputBox.KeyDown(keyCharacter);
                    }
                }
            }
            break;

            case VirtualKey.kType.kOther:
            {
                if (TextInputBox.TextField.Length <= MaxTextCount)
                {
                    char keyCharacter = _key.KeyCharacter;
                    if (mPressShift)
                    {
                        if (_key.HasShiftedChar())
                        {
                            keyCharacter = CHARACTER_TABLE[keyCharacter];
                        }
                        mPressShift = false;
                    }
                    TextInputBox.KeyDown(keyCharacter);
                }
            }
            break;

            case VirtualKey.kType.kSymbol_Star:
                //https://www.unicodepedia.com/groups/miscellaneous-symbols/
                /*WHITE STAR*/
                TextInputBox.KeyDown('\u2606');
                break;

            case VirtualKey.kType.kSymbol_Heart:
                /*WHITE HEART*/
                TextInputBox.KeyDown('\u2661');
                break;
            }
        }
    }