Your Digital Media Has Never Looked So Good

 
Suitie
Topic Author
Posts: 2
Joined: Tue May 16, 2017 8:44 am

left and right always fired twice!!

Tue May 16, 2017 9:12 am

First of all, I am a very beginner in Roku development, so I am sorry if my question is silly... I've followed all tutorials available and now I am trying to create a little app just to learn... but i get an "error" in the simplest function, and I am frustrated
My code:
'''
sub init()
     m.top.setFocus(true)
End sub
function onKeyEvent(key as String, press as Boolean) as Boolean
    if (key = "left") then 
        print "pressing left"
        return true
    end if
    if (key = "right") then 
        print "pressing right"
        return true
    end if
    return false
end function
'''
What I get when I press "left":
pressing left
pressing left
OnKeyEvent is fired twice whenever I press a key, the first one when the key is down, and the second one when it is up. Why is this happening? Where is the mistake? 
 
User avatar
squirreltown
Posts: 693
Joined: Sun Apr 21, 2013 2:20 pm

Re: left and right always fired twice!!

Tue May 16, 2017 9:47 am

Button press and button release are two different events.
Kinetics Screensaver (kineticsscreensaver), Kinetics³ Screensaver(kinetics3), Kinetics Painter Screensaver (kineticspainter), Kinetics Splash Screensaver (kineticssplash)
 
User avatar
RokuNB
Posts: 109
Joined: Fri Mar 31, 2017 2:22 pm

Re: left and right always fired twice!!

Tue May 16, 2017 10:11 am

Check the `press` param - the first time it's `true`, the second - `false`. You get notified once when user presses the button and 2nd time when they release it - this is helpful e.g. when writing games or scrolling through lists. It's up to you to decide which one of the 2 cases is the action item for you.

onKeyEvent() wrote:
The press parameter is a boolean value that is true if the key was pressed, and false if the key was released.
 
Suitie
Topic Author
Posts: 2
Joined: Tue May 16, 2017 8:44 am

Re: left and right always fired twice!!

Wed May 17, 2017 2:21 am

Thank you! I get it now 

Who is online

Users browsing this forum: No registered users and 3 guests