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: 
gbechtinger
Visitor

How to detect multiple buttons at the same time?

Hi!
Someone knows how to detect multiple buttons pressed at the same time?

Currently I'm using this to get the pressed or released keys:

msg = port.GetMessage()
if (type(msg) = "roUniversalControlEvent")
code = msg.GetInt()
if(code = 106)
0 Kudos
6 REPLIES 6
destruk
Streaming Star

Re: How to detect multiple buttons at the same time?

With the SDK I don't think "at the same time" is accurate - as a msg can only hold a single event per cycle.
What you're looking for here would be "held down while other buttons are already pressed" would be closer to what you can do.

How to do that -
for a simple two-button combination


CodeA=0
CodeB=0

msg=port.GetMessage()
if type(msg)="roUniversalControlEvent"
code=msg.GetInt()
if code=113
CodeA=0 'Select is released
elseif code=13 'Select is Pressed
CodeA=1
if CodeB=1
'both buttons are down
end if
elseif code=106
CodeB=0 'Play/Paused is released
elseif code=6 'Play/Paused is pressed
CodeB=1
if CodeA=1
'both buttons are down
end if
end if
end if


Something like that might work - at least on an roScreen where the UniversalControlEvent is available (as TheEndless mentioned in a different thread).
0 Kudos
destruk
Streaming Star

Re: How to detect multiple buttons at the same time?

edited for corrections...
0 Kudos
gbechtinger
Visitor

Re: How to detect multiple buttons at the same time?

Hi, thanks for the reply!

I'll try to explain what I need again:

1. when the user press the b button, I detect and start the behavior B.

2. if the user release the b button, I detect and stop the behavior B.

3. if the user press and not release the B button, the behavior B will stay active.

4. If the user press the A button while pressing the B, I cannot detect the pressing of A button.
0 Kudos
gbechtinger
Visitor

Re: How to detect multiple buttons at the same time?

I imagine that when the button B are being pressed, no message will be generated, so I could be able to detect the pressing of the A button, right?
0 Kudos
gbechtinger
Visitor

Re: How to detect multiple buttons at the same time?

"destruk" wrote:
With the SDK I don't think "at the same time" is accurate - as a msg can only hold a single event per cycle.
What you're looking for here would be "held down while other buttons are already pressed" would be closer to what you can do.

How to do that -
for a simple two-button combination


CodeA=0
CodeB=0

msg=port.GetMessage()
if type(msg)="roUniversalControlEvent"
code=msg.GetInt()
if code=113
CodeA=0 'Select is released
elseif code=13 'Select is Pressed
CodeA=1
if CodeB=1
'both buttons are down
end if
elseif code=106
CodeB=0 'Play/Paused is released
elseif code=6 'Play/Paused is pressed
CodeB=1
if CodeA=1
'both buttons are down
end if
end if
end if


Something like that might work - at least on an roScreen where the UniversalControlEvent is available (as TheEndless mentioned in a different thread).


I'm already doing what you said. I use a variable to hold that the B button was pressed and when it is released I mark this variable. But in the next screen refresh cycles, while the B button is being pressed, the GetMessage() does not return any code when I press others buttons.
0 Kudos
destruk
Streaming Star

Re: How to detect multiple buttons at the same time?

In that case it's not going to work.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.