简体   繁体   中英

onKeyEvent handling OK button

Some interesting behavior. When I use

else if key = "OK" and m.streambutton.hasFocus()
    print("OK BUTTON WORKING")
    handled = true

nothing prints to the console.

If I change "OK" to any other button such as "play" when I press that button while the button is highlighted the print handles correctly. For example:

else if key = "play" and m.streambutton.hasFocus()
    print("OK BUTTON WORKING")
    handled = true

Here is my whole function:

function onKeyEvent(key as String, press as Boolean) as Boolean
    handled = false
    m.keys = m.top.findNode("streamcodekeyboard")
    m.streambutton = m.top.findNode("streamcodeenter")

    if press
        if key = "down" and not m.keys.hasFocus()
            m.keys.setFocus(true)
            handled = true
        else if key = "up" and not m.keys.hasFocus()
            m.keys.setFocus(true)
            handled = true
        else if key = "right" and not m.streambutton.hasFocus()
            m.streambutton.setFocus(true)
            handled = true
        else if key = "OK" and m.streambutton.hasFocus()
            print("OK BUTTON WORKING")
            handled = true
        end if
    end if

    return handled
end function

Is there something unique about the "OK" button I am missing?

From the code, it seems " m.streambutton " is a button that has the focus right now. in this case "OK" button selection will be captured by " m.streambutton " and as you may not be having the code to handle this. There is " buttonSelected " filed for button that can be observed to handle the button selection ie " OK " button press. To get this work, after creating button, add observer for " buttonSelected " field in the code--

m.streambutton.observeField("buttonSelected", "streamBUttonSelected")

" streamButtonSelected " is a function that you have to write to handle the button selection--

function streamButtonSelected()
    print "stream button selected. write your code to handle button selection"
end function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM