Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
partyk1d24
Level 7

Multiple button clicks at the same time

I am working on a game idea and I am testing out the button presses. I augmented one of the templates and added this script.


Sub showImageCanvas()
canvasItems = [
{
Text:"Hello ImageCanvas"
TextAttrs:{Color:"#FFCCCCCC", Font:"Medium",
HAlign:"HCenter", VAlign:"VCenter",
Direction:"LeftToRight"}
TargetRect:{x:390,y:357,w:500,h:60}
}
]

canvas = CreateObject("roImageCanvas")
port = CreateObject("roMessagePort")
canvas.SetMessagePort(port)
'Set opaque background
canvas.SetLayer(0, {Color:"#FF000000", CompositionMode:"Source"})
canvas.SetRequireAllImagesToDraw(true)
canvas.SetLayer(1, canvasItems)
canvas.Show()
while(true)
msg = wait(0,port)
if type(msg) = "roImageCanvasEvent" then
if (msg.isRemoteKeyPressed()) then
i = msg.GetIndex()
' print "Key Pressed - " ; msg.GetIndex()
' removing I need up for my game yo!
' if (i = 2) then
if(i = 0 ) then
' Up - Close the screen.
canvas.close()
else if(i=17) then
print "Key Pressed - A"
else if(i=18) then
print "Key pressed - B"
else if(i=2) then
print "Left"
else if(i=3) then
print "right"
else if(i=4) then
print "down"
else if(i=5) then
print "up"
else
print i;
end if

else if (msg.isScreenClosed()) then
print "Closed"
return
end if
end if
end while
End Sub


From this I can see when the buttons are pressed, however, if I press 2 at the same time the result is unpredictable. Also it seems that once one key gets the nod (aka is shown in the print window) the other one never gets seen. Is there an onButtonUp call or something to keep track of this sort of thing. Admittedly, I am new to this (just got it for xmas) so I don't understand threading or any of these concepts quite yet but is there a good example of this?
0 Kudos
8 REPLIES 8\
NewManLiving
Level 8

Re: Multiple button clicks at the same time

Button up events as far as I know are not
Available to the imagecanvas. They are available
To roscreen using the 2d API If you are writing
A game which involves movement of graphics
You will get much better performance and
Much more control over key presses using
The 2d API
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
partyk1d24
Level 7

Re: Multiple button clicks at the same time

Can you speak to this a little more, possibly give me a link to these events. As long as I can draw with pixels or possibly compressed jpg style that would be fine.
0 Kudos
NewManLiving
Level 8

Re: Multiple button clicks at the same time

If you have the SDK the examples have
Some interesting 2D API source code
Which will help you to learn.
Basically you will use the roScreen
Object. This is single or double buffered
Video memory to which you write directly
At the lowest level currently available
Along with this you use roBitmap to create
Or load your graphics. Within a bitmap you
Can create regions using roRegion. These
Regions know how to scroll and wrap if needed
These regions can be placed in sprites which
Allow you to layer your graphics in a Z order
Sprites can also be animated. You also have
A compositor or container for your sprites
Which is a nice feature since it probably is
The fastest way to draw. Using more than one
Compositor allows you build an entire application
Using a single double buffered roScreen
You just simply swap out compositors
This provides complete control with a modest
Memory footprint. Of course you do a lot of
Coding. But the more you use it the easier it is
Look up the objects mentioned and you will
Have a good idea of how it works. Don't be
Put off after a short time it's no more difficult
Than the other levels of interface which are more
Limited
My Channels: 2D API Framework Presentation: https://owner.roku.com/add/2M9LCVC
Updated: 11-11-2015 - Completed Keyboard interface
The Joel Channel ( Final Beta )
0 Kudos
partyk1d24
Level 7

Re: Multiple button clicks at the same time

I appreciate what you are saying but that is way to advanced for what I am doing. I just basically want to forward a game to my TV using roku. To do this I have little control over the way the graphics are rendered.

Back to the question I asked I used the Debug Console to look at bslCore and I see this...


function bslUniversalControlEventCodes()

return {
BUTTON_BACK_PRESSED : 0
BUTTON_UP_PRESSED : 2
...
BUTTON_BACK_RELEASED : 100
BUTTON_UP_RELEASED : 102


This means it should be possible from any component (from my understanding of BrightScript). This leads me to other questions such as how does it queue the button presses, like why when I press one button and then before releasing another button do I not see the second button's event. Going to have to start doing some deep diving into the bslCore file I guess.
0 Kudos
partyk1d24
Level 7

Re: Multiple button clicks at the same time

I just tried the following...

Else if type(msg) = "roImageCanvasEvent" then
if (msg.isRemoteKeyPressed()) then
i = msg.GetIndex()
else if(i=17) then
print "Key Pressed - A"
else if(i=117) then
print "Key Released - A"


But all I see is

Key Pressed - A
Key Pressed - A


So I don't get it!
0 Kudos
RokuMarkn
Level 8

Re: Multiple button clicks at the same time

roImageCanvas only delivers key press events, not release events. You need to use roScreen to see the release events.

However, if you're holding down one button and press another one, you won't get the press event for the second button, no matter what screen type you're using. IR remotes send a continuous stream of messages while a button is held down, so it can't send messages for a second press during that time. I think you will just get a release for the first button when you press the second, and then a press for the first button when you release the second, but I wouldn't depend even on that.

--Mark
0 Kudos
partyk1d24
Level 7

Re: Multiple button clicks at the same time

Thanks, what if I use a bluetooth or wifi device? Then could I get multiple buttons at the same time? Is that even possible (use a bt dongle) on roku?
0 Kudos
RokuMarkn
Level 8

Re: Multiple button clicks at the same time

The only BT/wifi input devices supported are the Roku remotes that ship with the unit. The wifi remotes do not support multiple simultaneous button presses, and I'm pretty sure the BT remotes don't either.

--Mark
0 Kudos