/// <summary>
 /// Navigates down from the current key.
 /// </summary>
 /// <returns>The key below the current.</returns>
 public OnScreenKeyboardKey NavigateRight()
 {
     ActiveKey.RightKey.Text.color = AppliedKeyTextFocusColor;
     ActiveKey.Text.color          = AppliedKeyTextColor;
     ActiveKey = ActiveKey.RightKey;
     return(ActiveKey);
 }
        public void UpdateStructure()
        {
            Keys = new List <OnScreenKeyboardKey>(gameObject.GetComponentsInChildren <OnScreenKeyboardKey>());

            //Load the key list
            if (Keys.Count < 1)
            {
                Debug.LogWarning("Heathen On Screen Keyboard was unable to locate an OnScreeKeboardKey component in any of its children.\nPlease add at least 1 key or indicate a key on the OnScreenKeyboard behaviour by setting the ActiveKey value.", this);
            }

            if (Keys.Count > 0 && (ActiveKey == null || !Keys.Contains(ActiveKey)))
            {
                //The developer didn't tell us where to start or gave us an orphan so pick the first child we found under us
                ActiveKey = Keys[0];
            }

            foreach (OnScreenKeyboardKey key in Keys)
            {
                key.Keyboard = this;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="OnScreenKeyboardArguments"/> class.
 /// </summary>
 /// <param name="KeyPressed">Key pressed.</param>
 public OnScreenKeyboardArguments(OnScreenKeyboardKey KeyPressed)
 {
     this.KeyPressed = KeyPressed;
 }
        // Update is called once per frame
        void Update()
        {
            //This example is meant to be verbose; it is recomended that you write your own handler

            if (Keyboard != null)
            {
                //For the up arrow
                if (Input.GetKeyUp(KeyCode.UpArrow))
                {
                    //Call navigate up on the keyboard to set the active key to the one directly above this one
                    //This will switch the active key of the keyboard to the one indicated by the key as beeing its UpKey
                    Keyboard.NavigateUp();
                }
                //For the down arrow
                else if (Input.GetKeyUp(KeyCode.DownArrow))
                {
                    //Call navigate down on the keyboard to set the active key to the one directly below this one
                    //This will switch the active key of the keyboard to the one indicated by the key as beeing its DownKey
                    Keyboard.NavigateDown();
                }
                //For the left arrow
                else if (Input.GetKeyUp(KeyCode.LeftArrow))
                {
                    //Call navigate left on the keyboard to set the active key to the one directly left of this one
                    //This will switch the active key of the keyboard to the one indicated by the key as beeing its LeftKey
                    Keyboard.NavigateLeft();
                }
                //For the right arrow
                else if (Input.GetKeyUp(KeyCode.RightArrow))
                {
                    //Call navigate right on the keyboard to set the active key to the one directly right of this one
                    //This will switch the active key of the keyboard to the one indicated by the key as beeing its RightKey
                    Keyboard.NavigateRight();
                }
                //For the return
                else if (Input.GetKeyUp(KeyCode.Return))
                {
                    //If the active key is a backspace type we need to edit or destination string removing a character
                    if (Keyboard.ActiveKey.type == KeyClass.Backspace)
                    {
                        //Only operate if we have characters to remove
                        if (WorkingString.Length > 0)
                        {
                            WorkingString = WorkingString.Remove(WorkingString.Length - 1, 1);
                        }
                    }
                    else                     //For all other keys we can simply apend the output from the ActiveKey call this will also return newLine for Return type keys
                    {
                        WorkingString += Keyboard.ActivateKey();
                    }
                }
                //For either of the shift keys
                //Note this is here for convenance and wouldn't be typical of an onscreen keyboard
                else if (Input.GetKeyUp(KeyCode.RightShift) || Input.GetKeyUp(KeyCode.LeftShift))
                {
                    Keyboard.SetCase(Keyboard.IsLowerCase);
                }
                //For the backspace key
                //Again a matter of convenance
                else if (Input.GetKeyUp(KeyCode.Backspace))
                {
                    if (WorkingString.Length > 0)
                    {
                        WorkingString = WorkingString.Remove(WorkingString.Length - 1, 1);
                    }
                }
                //For the escape key
                //This is simply for our demo to allow the player to clear the destination string
                else if (Input.GetKeyUp(KeyCode.Escape))
                {
                    WorkingString = "";
                }
                //For the mouse button
                else if (Input.GetKeyUp(KeyCode.Mouse0))
                {
                    //Cast a ray and see if we hit one of our keys
                    //We will build our ray off the main camera from the position of the cursor
                    Ray        mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
                    RaycastHit rayHit;
                    if (Physics.Raycast(mouseRay, out rayHit))
                    {
                        //If we hit somthing insure its an OnScreenKeyboardKey and belongs to us
                        GameObject          subject = rayHit.collider.gameObject;
                        OnScreenKeyboardKey key     = subject.GetComponent <OnScreenKeyboardKey>();
                        if (key != null && key.Keyboard == Keyboard)
                        {
                            //Set the hit key as the active key of the keyboard
                            Keyboard.ActiveKey = key;
                            //Just like before we want to test if this is a backspace key if so we need to trim off our destination string
                            if (Keyboard.ActiveKey.type == KeyClass.Backspace)
                            {
                                if (WorkingString.Length > 0)
                                {
                                    WorkingString = WorkingString.Remove(WorkingString.Length - 1, 1);
                                }
                            }
                            else                             //if its any other type we will simply append the output from ActivateKey
                            {
                                WorkingString += Keyboard.ActivateKey();
                            }
                        }
                    }
                }
                //This is here just for demo and allows us to capture scroll movement from the mouse
                float scrollValue = Input.GetAxis("Mouse ScrollWheel");
                if (scrollValue != 0)
                {
                    //Get the keyboards current color
                    Color temp = Keyboard.KeyboardColor;
                    //set up holders for the hue saturation and value
                    float h, s, v = 0;
                    //convert our RGB to an HSV (HueSaturationValue) color
                    ColorToHSV(temp, out h, out s, out v);
                    //Incrament our hue value and boost the scroll movement a bit
                    h += scrollValue * 20;
                    //convert the HSV back to an RGB and reapply our original alpha value
                    temp = ColorFromHSV(h, s, v, temp.a);
                    //Update the color of the keyboard
                    Keyboard.KeyboardColor = temp;
                    //Now we do the same with the text color of the keyboard
                    temp = Keyboard.KeyTextColor;
                    ColorToHSV(temp, out h, out s, out v);
                    h   += scrollValue * 20;
                    temp = ColorFromHSV(h, s, v, temp.a);
                    Keyboard.KeyTextColor = temp;

                    //Once we have updated our colors its a good idea to force an ApplyColoring; the keyboard will test for some common changes and call
                    //this on its own but since we are here we might as well help it out
                    Keyboard.ApplyColoring();
                }
            }
            //Finaly update the destination string by setting its value to the text mesh and append the cursor so the player can see we are an input field
            InputText.text = WorkingString + cursor;
        }