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: 
lock_4815162342
Channel Surfer

OnKeyEvent not being triggered

I am learning SceneGraph and I am working with the SimpleGridWithVideoAndDetails sample. I have been able to successfully make some changes to the sample. I have read the documentation about the OnKeyEvent and the information is limited. 

I have changed the app to play a stream at launch. When the app loads, my video player plays the content as expected but when I press the back key the app closes and I don't get any error messages and I can see that the OnKeyEvent is not being called. :? I recently moved some things to my Main.brs, including the OnKeyEvent function, because I was having some issues referencing a node in HomeScene from Main. 

:?:Can the OnKeyEvent function be in any of the brs files, if not what are the restrictions about where it can be? 
:?:Must there only be one OnKeyEvent or can you have multiple ?
:?:Is it required to set the OnKeyEvent or is it implicit?
:?:Is there any other information that I might be missing about OnKeyEvent?

Thank you very much for taking the time to read this. Any information, not mater how small, will be greatly appreciated. 🙂 🙂
0 Kudos
2 REPLIES 2
joetesta
Roku Guru

Re: OnKeyEvent not being triggered

as i understand, 
1) any component can have an onKeyEvent function
2) your channel can have multiple listening onKeyEvent functions simultaneously, the lowest (focused) one will get hit first then on up the tree.
3) the values for "key" and "press" will be set by the firmware and passed to your components.

hope this might help.
aspiring
0 Kudos
sanitycheck
Visitor

Re: OnKeyEvent not being triggered

I'm learning this stuff too. (Disclaimer: Might be wrong)

OnKeyEvent works in any visual SceneGraph component, i.e. a scenes and 'group' derivatives. Put it in any .brs linked to a SG XML file in the <script uri> or directly in the <script> (but I assume nobody does that.) I don't think it'll work in main.brs - but maybe it does! That'll be outside the SceneGraph stuff though.

You can have multiple onKeyEvent functions, when you press a button it should first trigger the onKeyEvent closest to the currently focused node and then bubble up towards the onKeyEvent on the scene.

You can stop it bubbling up by returning true. (So, you can have a nested component that handles left and right, and lets the parent handle everything else - as a simple example.)
0 Kudos