Roku How to get standard input in Main.brs

259 views Asked by At

I am writing a Roku application and I need to read a string from the standard input. I am aware that to print to the standard output I can use the function print, but I need to give to the user the launches the script the possibility to insert new parameters at run time, for example (pseudo-code):

print "Enter server IP: "
string ip = getline();
print "Server IP " + ip

Is there a way to do it?

2

There are 2 answers

0
U.Mitic On

You would need to add Keyboad*** component to your Scene.xml file:

<Keyboard
    id = "keyboard" 
/>

After that add a Button component in Scene.xml, declare it in Scene.brs - init() function and set observer field on "buttonSelected".Also declare keyboard and set focus on it:

init() :

m.keyboard = m.top.findNode("keyboard")
m.keyboard.setFocus(true)
m.button = m.top.findNode("button")
m.button.observeField("buttonSelected","onButtonSelected")

Then create a Sub to get a user input from Keyboard when button is pressed:

Sub onButtonSelected()
    print m.keyboard.textEditBox.text
End Sub

***Note that Keyboard component has TextEditBox build in so you don't have to add it manually in Scene.xml file.

0
Nas Banov On

There is no "standard input" concept in Roku development. There are a few way your code can take external input though.

One is as mentioned above by @U-Mitic - to use component with keyboard input from the remote control, like roKeyboardScreen or KeyboardDialog RSG node and the like.

Another is to send such information externally over http by using ECP (Roku's External Control Protocol) - either /input or /launch w/params