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
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.
Writing a VB script is very easy.
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?
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
Writing a Java script is very easy.
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?
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!
//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);
}
Java script tutorial: http://www.w3schools.com/js/default.asp
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 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)
|
Displays the text Text on the phone. 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:
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)
|
Display the text Text on the phone with the title Title. Return: -
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: -
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: -
|
||||||||||||||||||
|
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: -
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: -
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: -
|
||||||||||||||||||
|
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: -
|
||||||||||||||||||
|
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: -
|
||||||||||||||||||
|
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: -
|
||||||||||||||||||
|
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: -
|
||||||||||||||||||
|
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)
|
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.
|
||||||||||||||||||
|
void Vibrate(int MSec) |
Vibrate the phone
|
||||||||||||||||||
| void Debug(sting/int Value) |
Print the value to the debug window.
|
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.
|
|
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 |
|
|||||||||||||||||||||
| DisplayTitleDialog |
|
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 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
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);
}
}