title: How to use buttonSelected in Roku Scenegraph application
body: <p>I am making a user entry using KeyBoard dialog. I have kept two buttons "OK" and "CANCEL". But on using <code>buttonSelected</code> it is calling both the button using observeField. Now, can anyone tell me how to use <code>buttonSelected</code> index for getting action while clicking on one button as OK and Cancel</p>
  
  <p>
  
  <pre><code>sub init()
    m.top.backgroundURI = "pkg:/images/rsgde_bg_hd.jpg"
  
    example = m.top.findNode("instructLabel")
  
    examplerect = example.boundingRect()
    centerx = (1280 - examplerect.width) / 2
    centery = (720 - examplerect.height) / 2
    example.translation = [ centerx, centery ]
  
    m.top.setFocus(true)
  end sub
  
  sub showdialog()
    keyboarddialog = createObject("roSGNode", "KeyboardDialog")
    keyboarddialog.backgroundUri = "pkg:/images/rsgde_dlg_bg_hd.9.png"
    keyboarddialog.title = "Example Keyboard Dialog"
  
    keyboarddialog.buttons=["OK","CANCEL"]
    keyboarddialog.optionsDialog=true
  
    m.top.dialog = keyboarddialog
    print "hello"
   KeyboardDialog.observeField("buttonSelected","onKeyPress")
  ' KeyboardDialog.observeField("buttonSelected","onKeyPressCancel")
   print "world"
  end sub
  
  
  
  
  function onKeyPress()
      print "m.value:::&gt;&gt;"m.top.dialog.text
  end Function
  function onKeyPressCancel()
  
      print "Screen should close"
  end Function
  
  function onKeyEvent(key as String, press as Boolean) as Boolean
    if press then
      if key = "OK"
        showdialog()
  
        return true
      end if
  
      end if
  
  
    return false
  end function
  
  
  
  ]]&gt;
  </code></pre>