Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
btpoole
Channel Surfer

Simple Keyboard

I am trying to use keyboarddialog to create a simple keyboard to have user enter an email address. Nothing special. 

function setemail()
?"IN SETEMAIL"
keyboarddialog = createObject("roSGNode", "KeyboardDialog")
keyboarddialog.title= "Enter Email Address"
keyboarddialog.visible = true
keyboarddialog.buttons=["Continue","Cancel"]
m.key=keyboarddialog.keyboard
m.key.showTextEditBox= true
m.top.setFocus(true)
m.top.dialog = keyboarddialog
return m.key.text
end function

Function onKeyEvent(key as String, press as Boolean) as Boolean
      button_val = m.top.dialog.buttonSelected
        if not press then
            if key = "OK"
        if(button_val = 0)
       ?"EMAIL "m.key.text
        m.top.dialog.close = true
        return true
        else if (button_val = 1)
        Print "CANCEL"
       m.top.dialog.close = true
      return true
                      end if
                    end if
                end if
            return FALSE
            end function

My problem lies in the onKey function.  Each time I press OK to accept the character for the email, the onKey fires of course executing the button_val=0 so I never get the complete email put in because of this. Can somebody guide me as to fixing this?
Thanks
0 Kudos
2 REPLIES 2
belltown
Roku Guru

Re: Simple Keyboard

Have you tried doing what the documentation recommends?


Typically, you will want to set the KeyboardDialog node title field to prompt the user to enter the string, and add "OK" and "Cancel" buttons by setting the Dialog node buttons field to [ "OK", "Cancel" ], then observe the Dialog node class buttonSelected field to react when the user presses one of those buttons. At any time, the text field can be accessed to obtain the string entered by the user.


i.e. observe the buttonSelected field rather than listening for each individual keypress.
0 Kudos
btpoole
Channel Surfer

Re: Simple Keyboard

belltown, actually no I didn't but I will now. Guess I was think of the old keyboard. Guess it doesn't work exactly the same.  Thanks for pointing me in right direction.
0 Kudos