Example – Casio Naurtech CETerm Ver.5.5 Scripting Guide User Manual
Page 59
N
AURTECH
W
EB
B
ROWSER AND
T
ERMINAL
E
MULATION FOR
W
INDOWS
CE
AND
W
INDOWS
M
OBILE
CETerm Scripting Guide
Page 59
Example
The following example shows how a global hot-key may be assigned to cycle
between several running programs. This example also shows the use of several
OS.Window methods. The hot-key invokes a CETerm script that will check
which application is visible and switch to the next. The script is shown first. It
must be imported into any CE
Term script slot and marked “Load at Startup”.
// Switch between multiple applications
// Each appX name can be a regular expression or string
// Can be any number of applications named in arguments
function ToggleApplications( app1, app2 )
{
// Find current application
var i;
var top = OS.Window.GetTopmost();
var toptext = OS.Window.GetText( top );
var topindex = -1;
// DEBUG: OS.Alert("toptext='" + toptext + "'");
// Find argument that matches current foreground application
// If no match, will switch to app1.
for (i=0; i < arguments.length; ++i)
{
if (toptext.match( arguments[i] ))
{
topindex = i;
break;
}
}
// Find next application index
var nextindex = (topindex + 1) % arguments.length;
// DEBUG: OS.Alert("topindex=" + topindex +
// " nextindex=" + nextindex +
// " arg=" + arguments[nextindex] );
// Find next window
var wa = eval( OS.Window.GetList() );
for (i=0; i < wa.length; ++i)
{
// DEBUG: OS.Alert( "text='" + wa[i].text + "'" );
if (wa[i].text.match( arguments[nextindex] ))
{
OS.Window.SetTopmost( wa[i].hwnd );
}
}
}
The next step is to define the script that is run when the hot-key is pressed. This
script invokes ToggleApplications. Let
‟s assume this script is in Script #8.