The Google Virtual Keyboard API has been officially deprecated as of May 26, 2011. It will continue to work as per our deprecation policy.

Reference

  1. JavaScript Reference
    1. Constructor
    2. Methods
    3. Global methods
    4. Static method
  2. Layout code enum
  3. Troubleshooting

JavaScript reference

Constructor - google.elements.keyboard

All of the methods described in this section are implemented on the google.elements.keyboard namespace.

Constructor Description

google.elements.keyboard.Keyboard(layouts, textfieldIds)

Keyboard(layouts, textfieldIds) creates a new Virtual Keyboard instance, where:

  • layouts is an array of keyboard layouts to preload, specified in the form of the LayoutCode enum (for example, google.elements.keyboard.LayoutCode.RUSSIAN). The first layout is the default. See the LayoutCode enum for a complete list of supported scripts.

    Note: The API throws an exception if you supply an invalid value for the layouts array.

  • textfieldIds is an optional array containing strings of text field IDs or element references allowing you to attach the keyboard to the UI. If you don't supply the optional array, the same keyboard instance applies to any input box or text area on your page.

Methods

Method Description

.getLayout()

getLayout() has no arguments and returns the active layout for the keyboard object in the form of google.elements.keyboard.LayoutCode.

.isVisible()

isVisible() has no arguments and returns a boolean indicating whether the onscreen keyboard is visible for this keyboard instance.

.setLayout(layout)

setLayout(layout) changes the keyboard layout for this keyboard instance, where layout is a layout code in the form of google.elements.keyboard.LayoutCode.

setLayout() has no return value.

.setVisible(visible)

setVisible(visible) sets the visibility state for this keyboard instance, where visible is a boolean indicating whether the keyboard is visible.

setVisible() has no return value.

Global methods

Method Description

.getLayoutName(layout)

getLayoutName(layout) returns a string containing the name of the active layout in its native language, where layout is a layout code in the form of google.elements.keyboard.LayoutCode.

Static method

The following static method is implemented on the google.language namespace.

Static method Description

.setOnLoadCallback(callback)

.setOnLoadCallback(callback) is a static function that registers the specified handler function to be called once the page containing this call loads, where callback is a required function called when the containing document is loaded and the API is ready for use (e.g., after onLoad). This function is implemented on the google namespace (i.e., google.setOnLoadCallback(callback);)

.setOnLoadCallback() has no return value.

Note: Previous documentation recommended that you use the body element's onload attribute (<body onload="OnLoad()">). While this is a fine way to go when you are in complete control of the page and all code loaded by the page, this approach can cause problems with some runtimes that destroy your body.onload handler. setOnLoadCallback() does not have these problems, and therefore is the recommended method of registering a callback that calls your code when the API is fully loaded and ready for use.

LayoutCode enum

The google.elements.keyboard.LayoutCode enumeration maps name constants to layout codes. Note that layout code is not the same as language code, because it is possible to have multiple layouts, or input methods, for a single language.

var google.elements.keyboard.LayoutCode = {
  'ALBANIAN': 'sq',
  'ARABIC': 'ar',
  'ARMENIAN_EASTERN': 'hy_east',
  'ARMENIAN_WESTERN': 'hy_west',
  'BASQUE': 'eu',
  'BELARUSIAN': 'be',
  'BENGALI_PHONETIC': 'bn_phone',
  'BOSNIAN': 'bs',
  'BRAZILIAN_PORTUGUESE': 'pt_br',
  'BULGARIAN': 'bg',
  'CATALAN': 'ca',
  'CHEROKEE': 'chr',
  'CROATIAN': 'hr',
  'CZECH': 'cs',
  'CZECH_QWERTZ': 'cs_qwertz',
  'DANISH': 'da',
  'DARI': 'prs',
  'DUTCH': 'nl',
  'DEVANAGARI_PHONETIC': 'deva_phone',
  'ENGLISH': 'en',
  'ESTONIAN': 'et',
  'ETHIOPIC': 'ethi',
  'FINNISH': 'fi',
  'FRENCH': 'fr',
  'GALICIAN': 'gl',
  'GEORGIAN_QWERTY': 'ka_qwerty',
  'GEORGIAN_TYPEWRITER': 'ka_typewriter',
  'GERMAN': 'de',
  'GREEK': 'el',
  'GUJARATI_PHONETIC': 'gu_phone',
  'GURMUKHI_PHONETIC': 'guru_phone',
  'HEBREW': 'he',
  'HINDI': 'hi',
  'HUNGARIAN_101': 'hu_101',
  'ICELANDIC': 'is',
  'ITALIAN': 'it',
  'KANNADA_PHONETIC': 'kn_phone',
  'KAZAKH': 'kk',
  'KHMER': 'km',
  'KOREAN': 'ko',
  'KYRGYZ': 'ky_cyrl',
  'LAO': 'lo',
  'LATVIAN': 'lv',
  'LITHUANIAN': 'lt',
  'MACEDONIAN': 'mk',
  'MALAYALAM_PHONETIC': 'ml_phone',
  'MALTESE': 'mt',
  'MONGOLIAN_CYRILLIC': 'mn_cyrl',
  'MONTENEGRIN': 'srp',
  'NORWEGIAN': 'no',
  'ORIYA_PHONETIC': 'or_phone',
  'PAN_AFRICA_LATIN': 'latn_002',
  'PASHTO': 'ps',
  'PERSIAN': 'fa',
  'POLISH': 'pl',
  'PORTUGUESE': 'pt_pt',
  'ROMANI': 'rom',
  'ROMANIAN': 'ro',
  'RUSSIAN': 'ru',
  'SANSKRIT_PHONETIC': 'sa_phone',
  'SERBIAN_CYRILLIC': 'sr_cyrl',
  'SERBIAN_LATIN': 'sr_latn',
  'SINHALA': 'si',
  'SLOVAK': 'sk',
  'SLOVAK_QWERTY': 'sk_qwerty',
  'SLOVENIAN': 'sl',
  'SOUTHERN_UZBEK': 'uzs',
  'SPANISH': 'es_es',
  'SWEDISH': 'sv',
  'TAMIL_PHONETIC': 'ta_phone',
  'TATAR': 'tt',
  'TELUGU_PHONETIC': 'te_phone',
  'THAI': 'th',
  'TURKISH_F': 'tr_f',
  'TURKISH_Q': 'tr_q',
  'UIGHUR': 'ug',
  'UKRAINIAN_101': 'uk_101',
  'URDU': 'ur',
  'UZBEK_LATIN': 'uz_latn',
  'UZBEK_CYRILLIC_PHONETIC': 'uz_cyrl_phone',
  'UZBEK_CYRILLIC_TYPEWRITTER': 'uz_cyrl_type',
  'VIETNAMESE_TCVN': 'vi_tcvn',
  'VIETNAMESE_TELEX': 'vi_telex',
  'VIETNAMESE_VIQR': 'vi_viqr'
};

Troubleshooting

If you encounter problems:

  • Look for typos. Remember that JavaScript is a case-sensitive language.
  • Use a JavaScript debugger. Google Chrome has a full set of developer tools. In Firefox, you can use the JavaScript console or the Firebug. In IE, you can use the Microsoft Script Debugger.
  • Search the discussion group. If you can't find a post that answers your question, post your question to the group along with a link to a web page that demonstrates the problem.