GlovePIE:Batch File Script Launcher

From WiiLi

Jump to: navigation, search

The following was based on a basic batch file script launcher made by speaker219: http://www.wiili.org/forum/automatic-glovepie-script-launcher-t2259.html

The above launcher developed into a more complicated solution which was discussed here: http://www.wiili.org/forum/glovepie-batching-t2254-s14.html

The following code is used to open GlovePIE and executes a selected script through a batch file. There are 3 parts to this script: A batch file, a wiimote input script(optional), and code to launch/relaunch the script launcher when closing a script in GlovePIE(optional).

The first part of the code is of a batch file. A batch file is a normal text file with a .bat extension. You can make the batch file in notepad and save as ie."ScriptLauncher.bat".

Note this code kills all running instances of GlovePIE so if you have any opened unsaved work, save them before executing this file.

This file should be can be stored anywhere on your harddrive. You must adjust some of the settings of this file for this to work:

SET PIEPATH=<The location of GlovePIE.exe on your harddrive>
SET SCRIPTPATH=<The location of the directory containing scripts you would like to launch>
SET ENABLEWIIMOTE=<Set to 1 if you would like to use the wiimote for input>
SET CONTROLSCRIPT=<The location of the wiimote control script>

In the below example:
The wiimote control is disabled by default
SET ENABLEWIIMOTE=0
To enable
SET ENABLEWIIMOTE=1

The Paths needing to be adjusted are as follows:
SET PIEPATH=C:\Progra~1\GlovePIE029\GlovePIE.exe
SET SCRIPTPATH=C:\Progra~1\GlovePIE029\WiimoteScripts\
SET CONTROLSCRIPT=C:\Progra~1\GlovePIE029\WiimoteScripts\Input.pie

Progra~1 - Is the short name of Program Files (If there are any spaces in any of the paths then you may need to use short filename).

Once you have properly set the above variables you should be able to execute the file. Type in the name of the file or part of the name and then press tab or shift tab to use autocomplete. If you type in a name of a file that is not in the current directory a list of files with name starting with the entered data is displayed on screen.

@ECHO OFF
TITLE GlovePIE Script Launcher

REM Adjust DOS window colours
COLOR F0

TASKKILL /F /IM GlovePIE.exe

REM Sets variable values
SET IN=0

REM Path to GlovePIE.exe file
SET PIEPATH=C:\Progra~1\GlovePIE029\GlovePIE.exe
REM Path to directory containing scripts to launch
SET SCRIPTPATH=C:\Progra~1\GlovePIE029\WiimoteScripts\

REM Input required to exit batch execution
SET EXIT=\

REM Input required to list files in script directory
SET LIST=l

REM Enables/disables Wiimote input control (0=off, 1=on)
SET ENABLEWIIMOTE=0

REM Filename of wiimote control script
SET CONTROLSCRIPT=C:\Progra~1\GlovePIE029\WiimoteScripts\Input.pie

REM Runs wiimote control script if variable ENABLEWIIMOTE=1
IF %ENABLEWIIMOTE% == 1 START /MIN %PIEPATH% -%CONTROLSCRIPT%

REM Changes working directory to script directory
CD %SCRIPTPATH%

:TOP
CLS
REM Launcher menu
ECHO  --------------------------------------------------
ECHO ^|            GlovePIE Script Launcher              ^|
ECHO ^|==================================================^|
ECHO ^| Wiimote Controls:                                ^|
ECHO ^| -----------------                                ^|
ECHO ^| Left and Right - Type Letter                     ^|
ECHO ^| Up and Down    - Auto-Complete                   ^|
ECHO ^| A              - Execute Script                  ^|
ECHO ^| B              - Clear input text                ^|
ECHO ^| Home           - Toggle CapsLock                 ^|
ECHO ^|--------------------------------------------------^|
ECHO ^| To exit type: "%EXIT%"                                ^|
ECHO  --------------------------------------------------
ECHO.
ECHO Enter name of script to run:

REM Get input
SET /p IN=

REM Exit
IF %IN% == %EXIT% (
   TASKKILL /F /IM GlovePIE.exe
   EXIT )

IF EXIST %IN% GOTO LAUNCH
IF EXIST %IN%.PIE GOTO LAUNCH
REM List scripts
DIR %IN%* /B /P
PAUSE
GOTO TOP

REM Launch script
:LAUNCH
TASKKILL /F /IM GlovePIE.exe
CLS
ECHO Script Loading...
IF %ENABLEWIIMOTE% == 1 PING 127.0.0.1 -n 2
START %PIEPATH% -%IN%

The next part of the script is the optional wiimote input script. Basically the wiimote may be used to scroll through the letters of the alphabet using the d-pad left and right. Once you get to the letter which is the first letter of the file name of the script you would like to launch press the d-pad up or down buttons to autocomplete the filename. To clear the input use Wiimote.B, to execute the script press Wiimote.A. The "/" is a special character which is at the end of the alphabet or can be accessed by holding down the Wiimote.Home button. Entering this character closes GlovePIE and the batch file.

The wiimote control script in this example is located @: C:\Progra~1\GlovePIE029\WiimoteScripts\Input.pie

The above is the path which is set in the batch file.

Remember running this script is disabled by default in the batch file. To enable it you must change the following: SET ENABLEWIIMOTE=1

Here are the contents of the wiimote control script:

if !var.init
   var.Character = "\"
   var.init = true
endif

Enter = Wiimote.A
Esc = Wiimote.B
Shift && Tab = Wiimote.Up
Tab = Wiimote.Down

if Wiimote.Left
   if var.Count < 30 then var.Count++
   if var.Character = "a"
      var.Character = "\"
   elseif var.Character = "b"
      var.Character = "a"
   elseif var.Character = "c"
      var.Character = "b"
   elseif var.Character = "d"
      var.Character = "c"
   elseif var.Character = "e"
      var.Character = "d"
   elseif var.Character = "f"
      var.Character = "e"
   elseif var.Character = "g"
      var.Character = "f"
   elseif var.Character = "h"
      var.Character = "g"
   elseif var.Character = "i"
      var.Character = "h"
   elseif var.Character = "j"
      var.Character = "i"
   elseif var.Character = "k"
      var.Character = "j"
   elseif var.Character = "l"
      var.Character = "k"
   elseif var.Character = "m"
      var.Character = "l"
   elseif var.Character = "n"
      var.Character = "m"
   elseif var.Character = "o"
      var.Character = "n"
   elseif var.Character = "p"
      var.Character = "o"
   elseif var.Character = "q"
      var.Character = "p"
   elseif var.Character = "r"
      var.Character = "q"
   elseif var.Character = "s"
      var.Character = "r"
   elseif var.Character = "t"
      var.Character = "s"
   elseif var.Character = "u"
      var.Character = "t"
   elseif var.Character = "v"
      var.Character = "u"
   elseif var.Character = "w"
      var.Character = "v"
   elseif var.Character = "x"
      var.Character = "w"
   elseif var.Character = "y"
      var.Character = "x"
   elseif var.Character = "z"
      var.Character = "y"
   elseif var.Character = "\"
      var.Character = "z"   
   endif
   var.TypeChar = true
   wait ((300 - var.Count * 10)ms)
elseif Wiimote.Right
   if var.Count < 30 then var.Count++
   if var.Character = "a"
      var.Character = "b"
   elseif var.Character = "b"
      var.Character = "c"
   elseif var.Character = "c"
      var.Character = "d"
   elseif var.Character = "d"
      var.Character = "e"
   elseif var.Character = "e"
      var.Character = "f"
   elseif var.Character = "f"
      var.Character = "g"
   elseif var.Character = "g"
      var.Character = "h"
   elseif var.Character = "h"
      var.Character = "i"
   elseif var.Character = "i"
      var.Character = "j"
   elseif var.Character = "j"
      var.Character = "k"
   elseif var.Character = "k"
      var.Character = "l"
   elseif var.Character = "l"
      var.Character = "m"
   elseif var.Character = "m"
      var.Character = "n"
   elseif var.Character = "n"
      var.Character = "o"
   elseif var.Character = "o"
      var.Character = "p"
   elseif var.Character = "p"
      var.Character = "q"
   elseif var.Character = "q"
      var.Character = "r"
   elseif var.Character = "r"
      var.Character = "s"
   elseif var.Character = "s"
      var.Character = "t"
   elseif var.Character = "t"
      var.Character = "u"
   elseif var.Character = "u"
      var.Character = "v"
   elseif var.Character = "v"
      var.Character = "w"
   elseif var.Character = "w"
      var.Character = "x"
   elseif var.Character = "x"
      var.Character = "y"
   elseif var.Character = "y"
      var.Character = "z"
   elseif var.Character = "z"
      var.Character = "\"
   elseif var.Character = "\"
      var.Character = "a"
   endif
   var.TypeChar = true
   wait ((300 - var.Count * 10)ms)
else
   if Pressed(HeldDown(Wiimote.Home, 2s))
      var.Character = "\"
      var.TypeChar = true
   else
      var.TypeChar = false
      var.Count = 0
   endif
endif

if var.TypeChar
   press(Esc)
   wait 25ms
   release(Esc)
   
   if var.Character = "a"
      Press(a)
      wait 25ms
      Release(a)
   elseif var.Character = "b"
      Press(b)
      wait 25ms
      Release(b)
   elseif var.Character = "c"
      Press(c)
      wait 25ms
      Release(c)
   elseif var.Character = "d"
      Press(d)
      wait 25ms
      Release(d)
   elseif var.Character = "e"
      Press(e)
      wait 25ms
      Release(e)
   elseif var.Character = "f"
      Press(f)
      wait 25ms
      Release(f)
   elseif var.Character = "g"
      Press(g)
      wait 25ms
      Release(g)
   elseif var.Character = "h"
      Press(h)
      wait 25ms
      Release(h)
   elseif var.Character = "i"
      Press(i)
      wait 25ms
      Release(i)
   elseif var.Character = "j"
      Press(j)
      wait 25ms
      Release(j)
   elseif var.Character = "k"
      Press(k)
      wait 25ms
      Release(k)
   elseif var.Character = "l"
      Press(l)
      wait 25ms
      Release(l)
   elseif var.Character = "m"
      Press(m)
      wait 25ms
      Release(m)
   elseif var.Character = "n"
      Press(n)
      wait 25ms
      Release(n)
   elseif var.Character = "o"
      Press(o)
      wait 25ms
      Release(o)
   elseif var.Character = "p"
      Press(p)
      wait 25ms
      Release(p)
   elseif var.Character = "q"
      Press(q)
      wait 25ms
      Release(q)
   elseif var.Character = "r"
      Press(r)
      wait 25ms
      Release(r)
   elseif var.Character = "s"
      Press(s)
      wait 25ms
      Release(s)
   elseif var.Character = "t"
      Press(t)
      wait 25ms
      Release(t)
   elseif var.Character = "u"
      Press(u)
      wait 25ms
      Release(u)
   elseif var.Character = "v"
      Press(v)
      wait 25ms
      Release(v)
   elseif var.Character = "w"
      Press(w)
      wait 25ms
      Release(w)
   elseif var.Character = "x"
      Press(x)
      wait 25ms
      Release(x)
   elseif var.Character = "y"
      Press(y)
      wait 25ms
      Release(y)
   elseif var.Character = "z"
      Press(z)
      wait 25ms
      Release(z)
   elseif var.Character = "\"   
      Press(Backslash)
      wait 25ms
      Release(Backslash)
   endif
   var.TypeChar = false
endif

The third (optional) and final part of this code is a script section to put inside of the scripts you will launch so when you want to exit that script the script launcher will be relaunched so you can quickly start up another script.

You must adjust the following line: var.BatchFilePath = <Location of batch file on hard drive>

Remember this calls the batch file which kills all processes of GlovePIE so make sure you have saved any unsaved scripts!

Note if you store the wiimote input script in the same script directory of the scripts you will be launching then this code should also be added to the top of the input.pie script.

In the following example pressing and holding Wiimote A, B, One and Two will launch the script launcher. This combination may be changed to almost anything just as long as either it is likely to be an unused combination or the helddown time may be lengthened. Also you should ensure this combination does not conflict with any other exit methods of a script or there is the potential that method may exit the script before the batch file is executed. The exit combination does not really matter and could even be different for every scripts (just as long as you can remember how to exit each script).

//Hold down Wiimote.A & Wiimote.B & Wiimote.One & Wiimote.Two for 2 seconds to close the current
//script and execute batch file script launcher
if !var.init
   var.BatchFilePath = "C:\ScriptLauncher.bat"
   var.init = true
endif

if Pressed(HeldDown(Wiimote.A && Wiimote.B && Wiimote.One && Wiimote.Two, 2s))
   Execute(var.BatchFilePath)
endif
   
//Script contents here
Personal tools