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: 
renojim
Community Streaming Expert

Pressing Back on roKeyboardScreen causes strange behavior

I just noticed if I press the Back remote key on an roKeyboardScreen I get the isScreenClosed event, but the Back keypress stays in some queue and I get another roImageCanvasEvent-isRemoteKeyPressed with the Back key ID on the roImageCanvas that was under the roKeyboardScreen. I hope that makes sense. For what it's worth, the roKeyboardScreen and the roImageCanvas are not using the same message port.

I have a workaround to eat the keypress, but it shouldn't be necessary.

-JT
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
5 REPLIES 5
RokuKevin
Visitor

Re: Pressing Back on roKeyboardScreen causes strange behavio

renojim,

Do you have some example code that exhibits this behavior? If so, I will look into the problem.

Thanks,

--Kevin
0 Kudos
renojim
Community Streaming Expert

Re: Pressing Back on roKeyboardScreen causes strange behavio

The channel it comes from is pretty involved, so I'll strip it down to the bare minimum and make sure it still exhibits the problem.

-JT
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
renojim
Community Streaming Expert

Re: Pressing Back on roKeyboardScreen causes strange behavio

Here it is stripped down. The only way out of the keyboard screen is to press back, but the real code uses the screen button.
Sub RunUserInterface(aa as Object)
canvas = CreateObject("roImageCanvas")
port = CreateObject("roMessagePort")
canvas.SetMessagePort(port)
canvas.SetLayer(0, {Color:"#FF800000"})
canvas.SetRequireAllImagesToDraw(false)
canvas.Show()

kbport = CreateObject("roMessagePort")
screen = CreateObject("roKeyboardScreen")
screen.SetMessagePort(kbport)
screen.SetDisplayText("Enter number from 1 to 1000")
screen.SetMaxLength(4)
screen.AddButton(1,"Finished")
nbr = rnd(1000)
while true
screen.SetText(nbr.toStr())
screen.Show()
msg = wait(0,kbport)
if type(msg) = "roKeyboardScreenEvent" then
if msg.isScreenClosed() then
print "got screen closed"
exit while
end if
end if
end while

' eat possible Back button
msg = wait(100,port)
if type(msg) = "roImageCanvasEvent" then
if msg.isRemoteKeyPressed() then
print "Key Pressed - " ; msg.GetIndex()
end if
end if
End Sub

Just to verify, I tried using the same message port for both screens and the "roImageCanvasEvent" still occurs.

-JT
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos
RokuKevin
Visitor

Re: Pressing Back on roKeyboardScreen causes strange behavio

Since screen never goes out of scope in your code sample, it is never popped off the display stack... If you want both screens in the same function as you have done (not recommended) you could just set screen to invalid, or call screen.close() to make sure the display stack is popped.

Modified Example code:

Sub RunUserInterface(aa as Object)
canvas = CreateObject("roImageCanvas")
port = CreateObject("roMessagePort")
canvas.SetMessagePort(port)
canvas.SetLayer(0, {Color:"#FF800000"})
canvas.SetRequireAllImagesToDraw(false)
canvas.Show()

kbport = CreateObject("roMessagePort")
screen = CreateObject("roKeyboardScreen")
screen.SetMessagePort(kbport)
screen.SetDisplayText("Enter number from 1 to 1000")
screen.SetMaxLength(4)
screen.AddButton(1,"Finished")
nbr = rnd(1000)
while true
screen.SetText(nbr.toStr())
screen.Show()
msg = wait(0,kbport)
if type(msg) = "roKeyboardScreenEvent" then
if msg.isScreenClosed() then
print "got screen closed"
exit while
end if
end if
end while
screen = invalid

' eat possible Back button
while true
msg = wait(0,port)
if type(msg) = "roImageCanvasEvent" then
if msg.isRemoteKeyPressed() then
print "Key Pressed - " ; msg.GetIndex()
else if msg.isScreenClosed() then
print "got screen closed"
exit while
end if
end if
end while
End Sub
0 Kudos
renojim
Community Streaming Expert

Re: Pressing Back on roKeyboardScreen causes strange behavio

They are in different functions in the real code; I just combined them here for a simple example. The keyboard screen has closed, the function with the keyboard screen has returned and it's several seconds later that the code gets back to the event loop for the image canvas. When it hits the event loop, the Back button shows up.

Even though screen has long since gone out of scope in the real code and this example is contrived, I tried adding screen=invalid to the example and the Back button still shows up as an image canvas event.

-JT
Roku Community Streaming Expert

Help others find this answer and click "Accept as Solution."
If you appreciate my answer, maybe give me a Kudo.

I am not a Roku employee.
0 Kudos