; Roku Remote v2.0 ; http://forums.roku.com/viewtopic.php?p=353412&sid=b2b387c6f19e31cb1f8208a6cbf4bbfb #include #include #include #include #include #include #Include ;;;;? #include "SSDPdiscover_Vroku.au3" ; in quotes to denote in this same directory AutoItSetOption ( "TrayAutoPause",0) ;0=no pause, 1=Pause Opt("MustDeclareVars", 1) ; 1 = Variables must be pre-declared Opt("GUICloseOnESC", 0) ;1=ESC closes, 0=ESC won't close Global $frmRemote, $frmSettings Global $filemenu Global $exititem Global $toolsmenu Global $settingsitem Global $hiddencommandsitem Global $helpmenu, $helpitem Global $aboutitem Global $btnBack, $btnHome, $btnUp, $btnLeft, $btnSelect, $btnRight, $btnDown, $btnReplay, $btnInfo Global $btnRewind, $btnPause, $btnForward, $btnSave_IP, $btnBitrate, $btnRestart, $btnDeveloper Global $WorkingRokuIP, $FileIPline, $hStatus, $msg, $lblDevice Global $looper, $txtdevicechecker, $rokuSocket local $btnClose_set $frmRemote = GUICreate("Roku Remote", 243, 300, 419, 171) ; Top MENU $filemenu = GUICtrlCreateMenu("&File") $exititem = GUICtrlCreateMenuItem("Exit",$filemenu) $toolsmenu = GuiCtrlCreateMenu("&Tools") $settingsitem = GUICtrlCreateMenuItem("Settings",$toolsmenu) $hiddencommandsitem = GUICtrlCreateMenuItem("Hidden Commands",$toolsmenu) $helpmenu = GuiCtrlCreateMenu("&Help") $helpitem = GUICtrlCreateMenuItem("Help",$helpmenu) $aboutitem = GUICtrlCreateMenuItem("About",$helpmenu) ; Typical Roku buttons $btnBack = GUICtrlCreateButton("Back", 20, 8, 83, 25, 0) $btnHome = GUICtrlCreateButton("Home", 140, 8, 83, 25, 0) $btnUp = GUICtrlCreateButton("Up", 96, 48, 50, 25, 0) $btnLeft = GUICtrlCreateButton("Left", 32, 88, 50, 25, 0) $btnSelect = GUICtrlCreateButton("Select", 96, 80, 50, 41, 0) $btnRight = GUICtrlCreateButton("Right", 160, 88, 50, 25, 0) $btnDown = GUICtrlCreateButton("Down", 96, 128, 50, 25, 0) $btnReplay = GUICtrlCreateButton("Replay", 20, 165, 83, 25, 0) $btnInfo = GUICtrlCreateButton("Info", 140, 165, 83, 25, 0) $btnRewind = GUICtrlCreateButton("Rewind", 32, 200, 50, 25, 0) $btnPause = GUICtrlCreateButton("Play/Pause", 86, 200, 70, 25, 0) $btnForward = GUICtrlCreateButton("Forward", 160, 200, 50, 25, 0) GUISetState(@SW_SHOW) ; see if the RokuRemote.ini file exists & read the IP if file exists Local Const $sFilePath = @ScriptDir & "\RokuRemote.ini" ; line added 1 Dec 2024 ; $RokuRemoteIPfile = FileOpen("RokuRemote.ini", 0) ; this is where Roku IP address is stored. 0 is read mode Local $RokuRemoteIPfile = FileOpen($sFilePath,0) ; adding "Local" to this line made it work ; Check if file opened for reading OK If $RokuRemoteIPfile = -1 Then ;MsgBox(0, "Notice", "No previously saved IP exist.") $WorkingRokuIP = "not defined" Else ; save IP to file $FileIPline = FileReadLine($RokuRemoteIPfile) ; read line 1 of the file ;MsgBox (0, "Saved IP:", $FileIPline) ;for testing to see IP saved to file $WorkingRokuIP = $FileIPline FileClose($RokuRemoteIPfile) EndIf $hStatus = _GUICtrlStatusBar_Create ($frmRemote, -1,"IP Setting = " & $WorkingRokuIP, -1) ;InstantReplay ;Info ;Backspace ;Search ;Enter ;Lit_ $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $btnSelect rokuCommand("Select") ; rokuCommand is a function at the bottom of this script Case $msg = $btnDown rokuCommand("Down") Case $msg = $btnUp rokuCommand("Up") Case $msg = $btnRight rokuCommand("Right") Case $msg = $btnLeft rokuCommand("Left") Case $msg = $btnPause rokuCommand("Play") Case $msg = $btnForward rokuCommand("Fwd") Case $msg = $btnRewind rokuCommand("Rev") Case $msg = $btnHome rokuCommand("Home") Case $msg = $btnBack rokuCommand("Back") Case $msg = $btnInfo rokuCommand("Info") Case $msg = $btnReplay rokuCommand("InstantReplay") Case $msg = $exititem Exit Case $msg = $settingsitem $frmSettings = GUICreate("Settings", 243, 100, 220, 171, -1,-1,$frmRemote) ; ROKU IP setting section $lblDevice = GUICtrlCreateLabel("Communication Settings:", 10, 10, 200, 20) $lblDevice = GUICtrlCreateLabel("Roku's IP Address: ", 18, 40, 100, 21) $WorkingRokuIP = GUICtrlCreateInput("192.168.1.", 113, 45, 110, 21) $btnSave_IP = GuiCtrlCreateButton("Save IP to file", 10, 65, 100, 20) GUISetState(@SW_SHOW) $RokuRemoteIPfile = FileOpen("RokuRemote.ini", 0) ; option 0 = read file mode ; Check if file opened for reading OK If $RokuRemoteIPfile = -1 Then MsgBox(0, "Notice", "No previously saved IP exist.") Else $FileIPline = FileReadLine($RokuRemoteIPfile, 1) ; read 1 line (line No. 1) from file GUICtrlSetData ($WorkingRokuIP, $FileIPline) ; set the $Working Roku IP to the IP read from file FileClose($RokuRemoteIPfile) EndIf $looper = 0 $txtdevicechecker = $WorkingRokuIP $msg = 0 While $looper = 0 $msg = GUIGetMsg() Select Case $msg = $btnSave_IP ; press button to save the ROKU IP address $RokuRemoteIPfile = FileOpen("RokuRemote.ini", 2) ; option 2 = write mode; erase previous contents first ; Check if file opened for writing OK If $RokuRemoteIPfile = -1 Then MsgBox(0, "Error", "Unable to create settings file.") Exit EndIf Dim $SaveIp = GUICtrlRead($WorkingRokuIP) FileWrite($RokuRemoteIPfile, $SaveIp) ; write IP into file FileClose($RokuRemoteIPfile) $WorkingRokuIP = $SaveIp MsgBox (48, "Save OK", "New IP saved!", 2) Case $msg = $GUI_EVENT_CLOSE GUISwitch($frmSettings) GUIDelete() $looper = 1 $msg = 0 GUISwitch($frmRemote) if $txtdevicechecker <> $WorkingRokuIP Then $hStatus = _GUICtrlStatusBar_Create ($frmRemote,-1,"IP Setting = " & $WorkingRokuIP,-1) EndIf EndSelect WEnd Case $msg = $hiddencommandsitem ; wid, ht, left, top, style, exStyle, parent $frmSettings = GUICreate("Hidden Commands", 268, 75, 210, 171,-1, -1,$frmRemote) $lblDevice = GUICtrlCreateLabel("Roku Hidden Tools", 40, 10,200,20) $btnBitrate = GUICtrlCreateButton("Bit Rate", 20, 40, 60, 25, 0) $btnRestart = GUICtrlCreateButton("Reboot", 95, 40, 60, 25, 0) ; To enable development mode: ; Before you are able to load a development application to your box, you must enable development mode on your Roku Streaming Player. ; When you enter the special remote control sequence: ; Home 3x, Up 2x, Right, Left, Right, Left, Right ; You will be presented with the Developer Settings page where you can enable developer mode on the box. $btnDeveloper = GUICtrlCreateButton("Developer", 170, 40, 80, 25, 0) GUISetState(@SW_SHOW) $looper = 0 $msg = 0 While $looper = 0 $msg = GUIGetMsg() Select Case $msg = $btnBitrate ; Home x 5, Rev x 3, Fwd x 2. See http://rokufordummies.wordpress.com/2013/06/ for more info rokuCommand("Home") sleep(500) rokuCommand("Home") sleep(500) rokuCommand("Home") sleep(500) rokuCommand("Home") sleep(500) rokuCommand("Home") sleep(500) rokuCommand("Rev") sleep(500) rokuCommand("Rev") sleep(500) rokuCommand("Rev") sleep(500) rokuCommand("Fwd") sleep(500) rokuCommand("Fwd") Case $msg = $btnRestart ; ??? this is developer mode according to http://mkvxstream.blogspot.com/2013/01/secret-roku-troubleshooting-screens.html rokuCommand("Home") sleep(500) rokuCommand("Home") sleep(500) rokuCommand("Home") sleep(500) rokuCommand("Up") sleep(500) rokuCommand("Up") sleep(500) rokuCommand("Right") sleep(500) rokuCommand("Left") sleep(500) rokuCommand("Right") sleep(500) rokuCommand("Left") sleep(500) rokuCommand("Right") Case $msg = $btnDeveloper ;?? this is reset according to http://mkvxstream.blogspot.com/2013/01/secret-roku-troubleshooting-screens.html rokuCommand("Home") sleep(500) rokuCommand("Home") sleep(500) rokuCommand("Home") sleep(500) rokuCommand("Home") sleep(500) rokuCommand("Home") sleep(500) rokuCommand("Up") sleep(500) rokuCommand("Rev") sleep(500) rokuCommand("Rev") sleep(500) rokuCommand("Fwd") sleep(500) rokuCommand("Fwd") Case $msg = $GUI_EVENT_CLOSE GUISwitch($frmSettings) GUIDelete() $looper = 1 $msg = 0 ExitLoop EndSelect WEnd case $msg = $aboutitem MsgBox (64, "About", "Roku Remote v2.0") case $msg = $helpitem ShellExecute ("rokuremotehelp.rtf") EndSelect WEnd ; #FUNCTION# ;=============================================================================== ; ; Name...........: rokuCommand($command) ; Description ...: Sends a command to the Roku via Port 8060 over WiFi ; Syntax.........: ; Parameters ....: ; Return values .: Success - Returns the data read from the file. ;========================================================================================== Func rokuCommand($command) Dim $rokuIp = $WorkingRokuIP ; get the Roku IP from the above script Dim $rokuPort = "8060" ; instead of port 8080 which went away with some firmware update TCPStartUp() ; start up the TCP service $rokuSocket = TCPConnect( $rokuIp, $rokuPort ) ; create a socket connected to an existing server (Roku) if @error Then MsgBox(4112, "Error", "TCPConnect failed: " & @error) ; an error of 10060 indicates server failed to respond (timeout) EndIf ;'POST /keypress/Lit_r HTTP/1.1\r\n\r\n' $command = 'POST /keypress/' & $command & ' HTTP/1.1' & @CRLF & @CRLF ;MsgBox(0, 'Error', $command) TCPSend($rokuSocket, $command) ; send the command to the Roku TCPCloseSocket($rokuSocket) ; close the socket TCPShutdown() ; shut down the TCP service Sleep(50) EndFunc