Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

static function Open(text: string, keyboardType: TouchScreenKeyboardType = TouchScreenKeyboardType.Default, autocorrection: bool = true, multiline: bool = false, secure: bool = false, alert: bool = false, textPlaceholder: string = ""): TouchScreenKeyboard;
static TouchScreenKeyboard Open(string text, TouchScreenKeyboardType keyboardType = TouchScreenKeyboardType.Default, bool autocorrection = true, bool multiline = false, bool secure = false, bool alert = false, string textPlaceholder = "");
static def Open(text as string, keyboardType as TouchScreenKeyboardType = TouchScreenKeyboardType.Default, autocorrection as bool = true, multiline as bool = false, secure as bool = false, alert as bool = false, textPlaceholder as string = "") as TouchScreenKeyboard

Parameters

textText to edit.
keyboardTypeType of keyboard (eg, any text, numbers only, etc).
autocorrectionIs autocorrection applied?
multilineCan more than one line of text be entered?
secureIs the text masked (for passwords, etc)?
alertIs the keyboard opened in alert mode?
textPlaceholderText to be used if no other text is present.

Description

Opens the native keyboard provided by OS on the screen.

The autocorrection determines whether the input tracks unknown words and suggests a more suitable replacement candidate to the user, replacing the typed text automatically unless the user explicitly overrides the action. The multiline determines if user can input more than one line of text. The secure identifies whether the keyboard is used for password. Text in the input field will be hidden from the user except the recently typed character. The keyboard can be opened in the alert mode too. The placeholder string will be displayed when there is no other text in the input field of the keyboard.

	var inputURL : String = "http://www.unity3d.com";
	private var keyboard : TouchScreenKeyboard;
	// Opens native keyboard optimized for URL entry
	function OnGUI() {
		if (GUI.Button(Rect(0, 10, 200, 32), inputURL))
			keyboard = TouchScreenKeyboard.Open(inputURL, TouchScreenKeyboardType.URL);

if (keyboard) inputURL = keyboard.text; }

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public string inputURL = "http://www.unity3d.com";
    private TouchScreenKeyboard keyboard;
    void OnGUI() {
        if (GUI.Button(new Rect(0, 10, 200, 32), inputURL))
            keyboard = TouchScreenKeyboard.Open(inputURL, TouchScreenKeyboardType.URL);
        
        if (keyboard)
            inputURL = keyboard.text;
        
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public inputURL as string = 'http://www.unity3d.com'

	private keyboard as TouchScreenKeyboard

	def OnGUI() as void:
		if GUI.Button(Rect(0, 10, 200, 32), inputURL):
			keyboard = TouchScreenKeyboard.Open(inputURL, TouchScreenKeyboardType.URL)
		if keyboard:
			inputURL = keyboard.text