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

How can I simulate keypress from within brightscript?

So my goal is to make the poster screen a little less annoying to use if it is initialized with only one playlist.

Currently, if you go to the poster screen with a single playlist, the user's focus is on the playlist name and the user has to hit the down arrow to allow selection of videos. This is lame. If there's only a single option, you shouldn't have a UI focus point for it.

So, first, I looked at the API for roPosterScreen to see if I can manually set the selection and focus of items. But I cannot.

So, then, I looked for any documentation for how to simulate keypress events and found nothing for inside of Brightscript.

I do have the "external control" pdf file, that suggests using a POST to the roku box itself. So I tried this (posting on the localhost):

Function simulateKeypress( key as String ) As Void
url = "http://127.0.0.1:8060/keydown/" + key
print "Simulating keypress: " key " as url " url
http = CreateObject("roUrlTransfer")
http.SetUrl( url )
http.PostFromString( "\r\n\r\n" )
End Function


But it didn't do anything useful.

Anybody have any ideas?
0 Kudos
4 REPLIES 4
TheEndless
Channel Surfer

Re: How can I simulate keypress from within brightscript?

The Roku doesn't support the loopback address, but you can get the IP address from the roDeviceInfo. There's an example in the in the roPosterScreen section of the component reference that uses the same method to launch the channel store from within a channel.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
renojim
Community Streaming Expert

Re: How can I simulate keypress from within brightscript?

"migmigmig" wrote:
Currently, if you go to the poster screen with a single playlist, the user's focus is on the playlist name and the user has to hit the down arrow to allow selection of videos. This is lame. If there's only a single option, you shouldn't have a UI focus point for it.

Are you referring to the filter banner (categories) at the top? If so, just don't use SetListNames and it won't be there.

-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
migmigmig
Visitor

Re: How can I simulate keypress from within brightscript?

Cool, omitting 'SetListNames' fixes that.

I'll look further into trying to pull the box IP so I can send keystrokes to myself. I didn't see any sample code for that in the "roPosterScreen" section of the ComponentReference.pdf, but I'll keep on greppin.

mig
0 Kudos
TheEndless
Channel Surfer

Re: How can I simulate keypress from within brightscript?

"migmigmig" wrote:
Cool, omitting 'SetListNames' fixes that.

I'll look further into trying to pull the box IP so I can send keystrokes to myself. I didn't see any sample code for that in the "roPosterScreen" section of the ComponentReference.pdf, but I'll keep on greppin.

mig

Make sure you've downloaded the latest 2.9 version of the SDK. The relevant sample code is...

function channelStoreGetFullVersion()
di = CreateObject("roDeviceInfo")
ipAddrs = di.GetIPAddrs()
ipAddr = ipAddrs.eth0
REM See the ECP document examples for how to obtain your plugin ID
url = "http://"+ ipAddr +":8060/launch/11?contentID=<PluginID>"
bodyString = ""
print "roku url: "; url
port = CreateObject("roMessagePort")
request = createObject("roUrlTransfer")
request.setPort(port)
request.setUrl(url)
response = request.asyncPostFromString(bodyString)
while true
msg = wait(0, port)
if type(msg) = "roUrlEvent"
if msg.getInt() = 1 then
print "Response code: "; msg.GetResponseCode()
if msg.GetResponseCode() = 404
response = invalid
else
response = msg.getString()
end if
exit while
end if
end if
end while
return response
end function

The eth0 is specific to the wired adapter, so you'll need to adjust based on the active network connection.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos