Bluetooth Remote Control Script guide

1. Introduction
2. VB Script Hello World
3. VB Script More Information
4. Java Script Hello World
5. Java Script Simple WinAMP
6. Java Script More Information
7. APIs
8. VB Script Help Functions
9. Java Script Help Functions

1 Introduction

Bluetooth Remote Control is a universal remote controller for the PC. See you PowerPoint slides in the phone, create keymaps or for full UI control write VB and Java Scripts. Download Bluetooth Remote Control at www.blueshareware.com.

 

This document describes how to write Java and VB scripts for Bluetooth Remote Control.

 

2 VB Script Hello World

Writing a VB script is very easy.

 

  1. In the applications view chose “New..” and VB script.
  2. Name the script to “Hello World VB” and copy and past the code below into the script.
  3. Press the “Refresh” button and the script will pop up in the phone main menu. (Only of you are already connected)

Const brcActivate = 1, brcBegin = 2, brcBack = 3, brcTimer = 9

Dim count
Dim outString

Select case BRCD.Action
    case brcActivate
            BRC.DisplayDialog "HelloWorld (VB Script)"
    case brcBegin
            BRC.StartTimer 1000
            count = 0
            BRC.SetStore 0,count
    case brcTimer
            count = BRC.GetStore(0)
            count = count + 1
            outString = "HelloWorld (VB)" & vbCrLf & count
            BRC.DisplayDialog outString

            BRC.SetStore 0,count
    case brcBack
            BRC.UnLoad
End Select

So what is happening when the user select the script in the phone?

  1. The first time the script is executed the BRCD.Action is set to brcActivate . The script must then display some UI on the phone (methods with prefix Display). This is done in the example with BRC.DisplayDialog.
  2. The script is then called with BRCD.Action set to brcBegin  in order to confirm that the script is running.  The timer is set to fire each second BRC.StartTimer and the variable is initialized BRC.SetStore (variable count at position 0)
  3. When the timer fires the stored variable value is retrieved with BRC.GetStore  (position 0) and the output string is constructed and displayed BRC.DisplayDialog. Finally the new variable is once again stored in permanent memory BRC.SetStore.
  4. When the user presses the back button on the phone the BRCD.Action is set to brcBack and the script calls  BRC.UnLoad to unload back to main menu.

3 VB Scripts More Information

Both the PowerPoint and the Itune applications are VB scripts. This document only describes the  Bluetooth Remote Control script API, so for more information please study those scripts as well as the tutorial below or others on Internet.

 

VB script tutorial: http://www.w3schools.com/vbscript/default.asp

 

4 Java Script Hello World

Writing a Java script is very easy.

 

  1. In the applications view chose “New..” and Java script.
  2. Name the script to “Hello World Java” and copy and past the code below into the script.
  3. Press the “Refresh” button and the script will pop up in the phone main menu. (Only of you are already connected)

        var brcActivate = 1, brcBegin = 2, brcBack = 3, brcTimer = 9;

        var CRLF = "\r\n";
        var count;
        var outString;

        switch (BRCD.Action)
        {
            case brcActivate:
                BRC.DisplayDialog("HelloWorld (Java Script)");
                break;
            case brcBegin:
                BRC.startTimer(1000);
                count = 0;
                BRC.SetStore(0,count);
                break;
            case brcTimer:
                count = BRC.GetStore(0);
                count = count + 1;
                outString = "HelloWorld (Java)" + CRLF + count;
                BRC.DisplayDialog(outString);

                BRC.SetStore(0,count);
                break;
            case brcBack:
                BRC.UnLoad();
                break;
            default:
        }

So what is happening when the user select the script in the phone?

  1. The first time the script is executed the BRCD.Action is set to brcActivate . The script must then display some UI on the phone (methods with prefix Display). This is done in the example with BRC.DisplayDialog.
  2. The script is then called with BRCD.Action set to brcBegin  in order to confirm that the script is running.  The timer is set to fire each second BRC.StartTimer and the variable is initialized BRC.SetStore (variable count at position 0)
  3. When the timer fires the stored variable value is retrieved with BRC.GetStore  (position 0) and the output string is constructed and displayed BRC.DisplayDialog. Finally the new variable is once again stored in permanent memory BRC.SetStore.
  4. When the user presses the back button on the phone the BRCD.Action is set to brcBack and the script calls  BRC.UnLoad to unload back to main menu.

 

5 Java Script Simple WinAMP

This script remote controls WinAMP. To do so it uses the SendMessage API which is extreamly powerful and allows remote controling to any application. For more information about SendMessage and how to remote control WinAMP please read the below links. WinAMP must be running!

How to use SendMessage to remote control applications!
Remote control WinAMP API!

  1. In the applications view chose “New..” and Java script.
  2. Name the script to “Simple WinAMP” and copy and past the code below into the script.
  3. Press the “Refresh” button and the script will pop up in the phone main menu. (Only of you are already connected)

        //Global variables
        var brcActivate = 1, brcBack = 3, brcKeyPress = 5;
        var windowClassName = "Winamp v1.x";
        var Stop = 1, Play = 2, Pause = 3;
        var CRLF = "\r\n";

        //Start executing main method
        main();

        //************************* Functions **************************
        function main()
        {
                //1. Detect which action that we have received
                switch (BRCD.Action)
                {
                        case brcActivate:
                                //Add timer object to detect changes done on PC
                                break;
                        case brcBack:
                                BRC.UnLoad();
                                return;
                                break;
                        case brcKeyPress:
                                KeyPress();
                                break;
                        default:
                }

            //2. Update display
            update();
        }

        function KeyPress()
        {
                switch (BRCD.Key)
                {
                        case "1":
                                //Write text in the debug window!
                                BRC.Debug("Play");
                                BRC.SendMessage(windowClassName,0x111, 40045, 0);
                                break;
                        case "2":
                                BRC.Debug("Pause");
                                BRC.SendMessage(windowClassName,0x111, 40046, 0);
                                break;
                        case "3":
                                BRC.Debug("Stop");
                                BRC.SendMessage(windowClassName,0x111, 40047, 0);
                                break;
                        default:
              }
        }

        function update()
        {
                var status;
                var text;

                status = BRC.SendMessage(windowClassName,0x400, 0, 104);
                if(status == 0)
                {
                        BRC.go_Button = Stop;
                }
                else if (status == 3)
                {
                        BRC.go_Button = Pause;
                }
                else
                {
                    BRC.go_Button = Play;
                }

                //Do not reflect the correct position only for a nicer UI
                BRC.go_Duration = 100;
                BRC.go_PlayerPostion = 20;


                //Construct a string with modifiers for UI control
                text = "<b><l>Simple WinAMP" + CRLF +"<s>WinAMP must be running";
                text = text + CRLF + CRLF + "<s>1: Play" + CRLF + "<s>2: Pause" + CRLF + "<s>3: Stop";
                BRC.DisplayDialog(text);
        }

 

6 Java Scripts More Information

Java script tutorial: http://www.w3schools.com/js/default.asp

 

7 APIs

There are two objects that the script can communicate with BRC and BRCD. BRC is used to carry data from the script to the phone and BRCD is used to carry data from the phone to the script.

7.1 BRC properties (get general phone status)

Name

Description

boolean CanShowImage

Return true if the phone can show images otherwise false.

 

int PhoneWidth

Return the phone screen size width.

 

int PhoneHeight

Return the phone screen size height.

 

int phoneClientVersion Return the phone client version. Supported from client 4.0 for older client 0 is returned

 

7.2 BRC methods (send data to phone)

Name

Description

 

 

WIN32

 

int SendMessage(string hWnd, int Msg, int wParam, long  lParam)

Send a message to the window hWnd

Return: status

 

hWnd is the classname e.g. Winamp v1.x for WinAMP

This function simulates the below WIN32 function SendMessage.

SendMessage is a powerful method to remote control any window. Please read this very interesting article to learn more.

boolean IsProcessRunning(string Name)

Is the process running
Return: true if the process is running otherwise false

Please observe that the .exe extension shall be removed. So to find the process name please write the exe file name without .exe

   

Display UI on phone

 

void DisplayDialog(string Text)

  • Used by the Itune script

  • Left softkey is set with SetLeftSoftKeyText

 

 

Displays the text Text on the phone.
Return: -

Each line that is terminated with carriage return + line feed will be displayed on a single row. If the text is bigger then the row it will be truncated and left aligned. The default line is centered aligned with normal size and plain style.

Following modifiers can be set to a text line:

 Modifier  Action
 <b>  Bold
 <l>  Large
 <s>  Small
<le>  Left aligned
 <ri>  Right aligned
<sp>  Empty row. The space varies depending on font size
<sc>  The line is scrolled if the line is bigger then the screen
<im>  Show image left align to text line. If a second text line is marked with <im> both lines will be aligned to the image
(Supported from client version 4.0)

 

It is also possible to add a UI object to the DisplayDialog. Please see section 7.5 Graphical Objects

 

void DisplayTitleDialog(string Title, string TopTitle, string Text)
  • Used by the PowerPoint script
  • Left softkey is set with SetLeftSoftKeyText
  • Deprecated! DisplayDialog is the prefered one to use

Display the text Text on the phone with the title Title.

Return: -

 

  • Title is centered with the size big
  • TopTitle is centered above the title small size
  • Text is left align normal size

The text is scrollable with up and down key! This also means that these key strokes are not available for the script!

It is also possible to add a UI object to the DisplayTitleDialog. Please see section 7.5 Graphical Objects
 

void DisplayText(string Title, string Text)

Display the text Text on the phone with the title Title.

Return: -

 

  • Title is centered with the size big
  • Text is left align normal size

The text is scrollable with up and down key. This also means that these key strokes are not available for the script!
 

void DisplayImage(string ImgPath, boolean DeleteImg)

Show the image ImgPath on the phone.

Return: -

 

  • ImgPath is the path to the image (supported formats BMP, jpg and gif)
  • If DeleteImg is true the image is deleted automatically otherwise it is not.

 

void DisplayMenu( string Title, string Row, boolean Last)

Display a menu on the phone. When displaying a menu the script typically calls this functions several times setting Last to true on the last function call. The menu is not shown until Last is true.

Return: -

 

  • Title is the window title
  • Row is the menu row
  • Last shall be set to true for the last menu row otherwise false

Please look at section 8 and 9 for the menu help functions
 

void DisplaySortedMenu(string Title, string Row, boolean Last)

Display a sorted menu on the phone. When displaying a menu the script typically calls this functions several times setting Last to true on the last function call. The menu is not shown until Last is true.

Return: -

 

  • Title is the window title
  • Row is the menu row
  • Last shall be set to true for the last menu row otherwise false

Please look at section 8 and 9 for the menu help functions
 

void DisplayPercentInput(string Text, int Percent)

Display a percent input window with the text Text.

Return: -

 

  • Text is written above the percent input control
  • Int between 0-100 setting the start position

 

void DisplayTextInput(string Title, string Text)

Display a input window with the title Title and initial text Text

Return: -

 

void DisplayProgress(string Text)

Display a progress window with the text Text.

Return: -

 

 

 

Timer

 

void StartTimer(int MSec)

Start the timer with the periodical intervals MSec.

Return: -

 

  • Time is set in mile seconds (e.g. one second 1000)

 

void StopTimer()

Stop the timer.

Return: -

 

 

 

Permanent store

 

void SetStore(int Index,int Value)

Store the value Value at index Index in permanent memory

Return: -

 

  • Index is an integer that must be bigger or equal to 0
  • Value is the value that is stored

 

int GetStore(int Index)

Return the integer value stored at index Index.

Return: The stored value

 

void SetObjStore(int Index, obj Object)

Store the object Object on index Index.

Return: -

 

  • Index is an integer that must be bigger or equal to 0
  • Object is an object. This can for example be an array or an object reference

 

obj GetObjStore(int Index)

Return the object stored at index Index.

Return: The generic object

 

void SetTextStore(int Index, string Text)

Store the text Text at index Index.

Return: -

 

  • Index is an integer that must be bigger or equal to 0
  • Text is the string that is stored

 

string GetTextStore(int Index)

Return the text stored at index Index.

Return: Stored string

 

 

 

Unload script

 

void UnLoad()

Unload the scripts and display the main menu.

Return: -

 

 

 

Graphical Objects  
void ResetTimeObject() Reset go_SimpleTime graphical object (see 4.6 Graphical Objects)
void StartTimeObject() Start go_SimpleTime graphical object  (see 4.6 Graphical Objects)
void StopTimeObject() Stop go_SimpleTime graphical object  (see 4.6 Graphical Objects)
   

Miscellaneous

 

void SetLeftSoftKeyText(String Text)
  • Supported from client version 4.0
Set the pop-up window text for the left softkey "More".
Return: -

This softkey  is visible after calling DisplayDialog or DisplayTitleDialog. The recommendation is to call this method when the script opens receiving brcActivate

Each line should be terminated with carriage return and be prefixed with one of below prefix. Selecting the line is the same as pressing the corresponding key.

  • 0:
  • 1:
  • 2:
  • 3:
  • 4:
  • 5:
  • 6:
  • 7:
  • 8:
  • 9:
  • <:
  • >:
  • ^:
  • v:
  • F:

 

void Vibrate(int MSec)

Vibrate the phone
Return: -
 

  • Vibrate mSec mili seconds

 

void Debug(sting/int Value)

Print the value to the debug window.

  • Value can be both a string and a integer

 

 

7.3 BRCD properties (data from phone to script)

Name

Description

int Action

This property carries what type of action that was done on the phone.

  • ACTION_Activate = 1;
  • ACTION_Begin = 2;
  • ACTION_Back = 3;
  • ACTION_Next = 4;
  • ACTION_KeyPress = 5;
  • ACTION_KeyRelease = 6;
  • ACTION_IntegerInput = 7;
  • ACTION_TextInput = 8;
  • ACTION_Timer = 9;

 

string Key

This property carries the key pressed as a string. This value is valid if the Action is ACTION_KeyPress or ACTION_KeyRelease.

“0”,”1”,”2”,”3”,”4”,”5”,”6”,”7”,”8”,”9”, “*”,”#”

”<”,”>”,”^”, ”v” ,”f”    (Joystick)

 

int IntInput

This property carries the integer input value. This value is valid if the Action is ACTION_IntegerInput.

 

string TextInput

This property carries the text input value. This value is valid if the Action is ACTION_TextInput.

 

string ProgramFolderPath

This property is the path to the local Program folder as a string

 

 

7.4 Possible actions in different UI windows

The action ACTION_Begin, ACTION_Back and ACTION_Timer is available in all UI windows

UI window

Action to receive

DisplayDialog

ACTION_Next, ACTION_KeyPress, ACTION_KeyRelease

DisplayTitleDialog ACTION_Next, ACTION_KeyPress, ACTION_KeyRelease (not ^ and v)

DisplayText

ACTION_Next

DisplayImage

ACTION_Next, ACTION_KeyPress, ACTION_KeyRelease

DisplayMenu

ACTION_IntegerInput

DisplaySortedMenu

ACTION_IntegerInput

DisplayPercentInput

ACTION_IntegerInput

DisplayTextInput

ACTION_TextInput

DisplayProgress

ACTION_Next, ACTION_KeyPress, ACTION_KeyRelease

 

7.5 Graphical Objects (when calling DisplayDialog or DisplayTitleDialog)

UI window

Action to receive

DisplayDialog

 

Variable name  Valid values  Description
go_Button Integer
  • Stop = 1
  • Play = 2
  • Pause = 3
Left and bottom aligned action icons
go_Duration
go_PlayerPostion
Integer Left aligned bottom time track bar
  • go_Duration Duration of track
  • go_PlayerPostion current track time
go_Mute boolean Set mute object
go_Shuffle boolean Set shuffle object
go_Repeat boolean Set repeat object
go_ImagePathDD

 

String Left aligned image that takes around 25% of the screen size

Path to bmp image. The image will be automatically deleted

 

 

DisplayTitleDialog  
Variable name  Valid values  Description
go_ImagePath String Left aligned image that takes around 25% of the screen size

Path to bmp image. The image will be automatically deleted

go_SimpleTime boolean Left aligned time object located directly below the title

The object is controlled via the Graphical Objects function call API

 

 

8 VB Script Help Functions

VB help function to make it easier to write the VB scripts for Bluetooth Remote Control

 

8.1 Show menu

This VB script function shows a sorted or unsorted menu on the phone with the array item as input.

 

Sub ShowMenu(title,item,sorted)

 

         Dim i

         Dim low

         Dim high

 

         low = LBound(item)

         high = UBound(item) - 1

 

         'Send all menu elements to the menu except the last one

         for i = low  to high

                  if sorted then

                           BRC.DisplaySortedMenu title,item(i),False

                  else

                           BRC.DisplayMenu title,item(i),False

                  end if

         next

 

         'Send the last menu element

         if sorted then

                  BRC.DisplaySortedMenu title,item(UBound(item)),True

         else

                  BRC.DisplayMenu title,item(UBound(item)),True

         end if

End Sub

 

9 Java Script Help Functions

Java help function to make it easier to write the Java scripts for Bluetooth Remote Control

 

9.1 Show menu

This Java script function shows a sorted or unsorted menu on the phone with the array item as input.

 

 

            function showMenu(title,menu,sorted)
            {
                    //Send all elements but the last one!
                    for (var i = 0; i < menu.length-1; i++)
                    {
                        if (sorted)
                        {
                            BRC.DisplaySortedMenu(title,menu[i],false);
                        }
                        else
                        {
                            BRC.DisplayMenu(title,menu[i],false);
                        }
                    }

                //Send last element
                if (sorted)
                {
                    BRC.DisplaySortedMenu(title,menu[menu.length-1],true);
                }
                else
                {
                    BRC.DisplayMenu(title,menu[menu.length-1],true);
                }
        }