AudioAsset
Ease
FastString
FontAsset
NineSlice
PackedSprite
PackedSpriteID
RB
   HardwareSettings
   IRetroBlitGame
RBAsset
Rect2i
ShaderAsset
SoundReference
SpriteGrid
SpriteSheetAsset
TMXMapAsset
   TMXLayer
   TMXLayerLoadState
   TMXObject
   TMXObjectGroup
   TMXProperties
Vector2i

RB.InputString

Method  -  Static

public static string InputString()

Parameters

No parameters.

Returns

string

Character string

Description

Returns a string of characters entered since last IRetroBlitGame.Update call. Normally this string will be 0 or 1 characters long, but it is possible that the user may quickly perform two key strokes within the spawn of a single game loop. This method is the preferred way of capturing user text input.

Example

string userInput = "";

void Update() {
    // Capture user input string from last frame
    string input = RB.InputString();

    // Iterate through the input and handle special characters
    for (int i = 0; i < input.Length; i++) {
        char c = input[i];

        // Any character with unicode value >= ' ' can just be used as-is
        if (c >= ' ') {
            userInput.Append(c);
        }
        // Handle backspace
        else if (c == (char)UnityEngine.KeyCode.Backspace && userInput.Length > 0) {
            userInput.Truncate(userInput.Length - 1);
        }
        // Handle enter/return
        else if (c == (char)KeyCode.Return) {
            Execute(userInput)
        }
    }
}

See Also

RB.KeyPressed
RB.KeyReleased
RB.KeyDown

See Docs

Features - Keyboard