📜  如何在 monogame 中将键状态转换为字母 - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:56.139000             🧑  作者: Mango

代码示例1
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);
    }