Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

Script language

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

TouchScreenKeyboard.Open

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static function Open(text: string, keyboardType: TouchScreenKeyboardType = TouchScreenKeyboardType.Default, autocorrection: bool = true, multiline: bool = false, secure: bool = false, alert: bool = false, textPlaceholder: string = ""): TouchScreenKeyboard;
public static TouchScreenKeyboard Open(string text, TouchScreenKeyboardType keyboardType = TouchScreenKeyboardType.Default, bool autocorrection = true, bool multiline = false, bool secure = false, bool alert = false, string textPlaceholder = "");
public 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

text Text to edit.
keyboardType Type of keyboard (eg, any text, numbers only, etc).
autocorrection Is autocorrection applied?
multiline Can more than one line of text be entered?
secure Is the text masked (for passwords, etc)?
alert Is the keyboard opened in alert mode?
textPlaceholder Text 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