Answers for "how to convert a key state to a letter in monogame"

C#
0

how to convert a key state to a letter in monogame

private string text = string.Empty;

    protected override void Update(GameTime gameTime)
    {
        KeyboardState keyboardState = Keyboard.GetState();
        Keys[] keys = keyboardState.GetPressedKeys();  // Get an array of all the pressed keys.

        if(keys.Length > 0)
        {
            var keyValue = keys[0].ToString();  // Get the first element of the array and convert it to a string.
            text += keyValue;  // Add it to text.
        }

        base.Update(gameTime);
    }
Posted by: Guest on July-17-2020

Code answers related to "how to convert a key state to a letter in monogame"

C# Answers by Framework

Browse Popular Code Answers by Language