Example #1
0
 void ChangeKeyBoardState(VirtualKeyButton button)
 {
     if (button.GetKeyCode(VirtualKeyState.Normal) == KeyCode.LeftShift)  //Shift
     {
         m_CapsShift = !m_CapsShift;
     }
     if (button.GetKeyCode(VirtualKeyState.Normal) == KeyCode.Numlock) //Input Change
     {
         m_NormalInputState = !m_NormalInputState;
     }
 }
Example #2
0
        public void ButtonPressed(GameObject keyObj)
        {
            VirtualKeyButton button = keyObj.GetComponent <VirtualKeyButton>();

            errorMsg = "";
            errorMsgParameter.Clear();
            if (button != null)
            {
                ChangeKeyBoardState(button);  //Get Set Keyboard State
                ShowKeyView();

                if (button.GetKeyCode(VirtualKeyState.Normal) == KeyCode.Escape)
                {
                    #region Escape
                    CloseKeyboard();
                    return;

                    #endregion
                }  //关闭按钮

                if (button.GetKeyCode(VirtualKeyState.Normal) == KeyCode.Return)
                {
                    #region Enter
                    if (handleInput != null)
                    {
                        handleInput(result, true, errorMsg, errorMsgParameter.ToArray());  //返回输入信息
                    }
                    GlobalEntity.GetInstance().Dispatch <bool>(VRKeyboardEvent.KeyBoardStateNotify, false);
                    gameObject.SetActive(false);
                    return;

                    #endregion
                }

                if (button.GetKeyCode(VirtualKeyState.Normal) == KeyCode.Backspace) //&& m_DisplayText.text.Length > 0)
                {                                                                   // remove last char
                    #region Backspace 回退
                    //   appendChar = "\b"; //回车
                    if (result.Length > 0)
                    {
                        result = result.Substring(0, result.Length - 1);
                    }
                    #endregion
                }
                else if (button.GetKeyCode(VirtualKeyState.Normal) == KeyCode.Clear)
                {
                    #region Clear
                    appendChar = "";
                    result     = "";
                    #endregion
                }
                else if (button.GetKeyCode(VirtualKeyState.Normal) == KeyCode.Numlock)
                {  //Numlock
                    appendChar = "";
                }
                else
                {
                    #region 其他
                    int len = Encoding.Default.GetBytes(result).Length;  //获取编码长度 区分汉字和字母
                    if (len >= inputRequest.m_Limite_Max && inputRequest.m_Limite_Max != 0)
                    {
                        result   = result.Substring(0, inputRequest.m_Limite_Max);
                        errorMsg = "900007";  //>输入字符应少于{0}个
                        errorMsgParameter.Add(inputRequest.m_Limite_Max);
                    }
                    else
                    {
                        if (button.GetKeyCode(VirtualKeyState.Normal) == KeyCode.Space)
                        {
                            appendChar = " ";
                        }
                        else
                        {
                            appendChar = button.GetKeyChar(keyboardState);
                        }

                        #region Check Input string type
                        switch (inputRequest.m_InputContenType)
                        {
                        case InputContenType.Standard:
                            result += appendChar;
                            break;

                        case InputContenType.Number:
                            if (InputCheckRule.IsNumber(appendChar))
                            {
                                result += appendChar;
                            }
                            else
                            {
                                errorMsg = "900004";     //输入不是数字
                            }
                            break;

                        case InputContenType.Character:
                            if (InputCheckRule.IsChar(appendChar))
                            {
                                result += appendChar;
                            }
                            else
                            {
                                errorMsg = "900005";     //输入不是字母
                            }
                            break;

                        case InputContenType.NumberAndCharacter:
                            if (InputCheckRule.IsChar(appendChar) || InputCheckRule.IsNumber(appendChar))
                            {
                                result += appendChar;
                            }
                            else
                            {
                                errorMsg = "900006";     //输入不是字母或者数字
                            }
                            break;

                        case InputContenType.Customer:       //customerDefine
                            if (inputRequest.m_InputCheckHandle != null)
                            {
                                if (inputRequest.m_InputCheckHandle(appendChar, ref result, out errorMsg, ref errorMsgParameter))
                                {
                                    result += appendChar;
                                }
                            }
                            else
                            {
                                result  += appendChar;
                                errorMsg = "Miss Customer Check Input Rule!!!! ";
                            }
                            break;
                        }
                        #endregion
                    }
                    #endregion
                }

                if (handleInput != null)
                {
                    handleInput(result, false, errorMsg, errorMsgParameter.ToArray());  //Return the input Result
                }
            }
        }