Search code examples
tvosapple-tvtvmltvjs

How to detect keyboard input with TVML/TVJS


As the title suggests, I would like to know how to detect keyboard input using a TVML template and using the TVJS design pattern found in the Apple Catalog Project

For example: when Search.xml.js is displayed, and the user selects the 'a' key on the keyboard, how can I detect that they have selected the 'a' key?


Solution

  • After digging into the Apple Docs I was able to find the answer.

    Here is the reference for Keyboard onTextChange

    Here is an example of it's use:

    var doc = Presenter.makeDocument(resource);
    var searchField = doc.getElementById("SearchField"); //I added an id to the searchField to make it easy to access.
    var keyboard = searchField.getFeature("Keyboard");
        keyboard.onTextChange = function () {                                
          swiftLog(keyboard.text);
        };