API's for External Programs/Scripts Interaction  >

www.perfectkeyboard.com

 

Windows Script (WScript)

 

The  Perfect Keyboard Professional edition (and Free Macro Player) comes with an Mtw.Proxy Windows Scripting object. It provides access to the variables and macros in running Perfect Keyboard. JScript or VBScript scripts can use MtwProxy object to set or retrieve a value of an application global variable (the one that starts with "ga_" prefix - see more here - or a system variable - see more here), and start an existing macro and retrieve its result.

 

Mtw.Proxy Object API Commands

 

Command

Description

GetVer()

Returns version (such as "9.2.0") of the  Perfect Keyboard Professional edition (or Free Macro Player).

var mtwProxy = WScript.CreateObject("Mtw.Proxy");

var version = mtwProxy.GetVer(); 

GetName()

Returns program name (such as Perfect Keyboard).

var mtwProxy = WScript.CreateObject("Mtw.Proxy");

var name = mtwProxy.GetName();

GetVar(VARIABLE_NAME)

Returns a variable value.

var mtwProxy = WScript.CreateObject("Mtw.Proxy");

var value = mtwProxy.GetVar(VARIABLE_NAME);

VARIABLE_NAME - a string that specifies an existing global application scope variable (starting with "ga_" prefix) or a system variable. It can be also an array element (for example, "ga_MyArray[3]).

 

SetVar(VARIABLE_NAME, NEW_VALUE)

Sets the variable value and returns "1" (on success) or "0" (on fail).

var mtwProxy = WScript.CreateObject("Mtw.Proxy");

var success = mtwProxy.SetVar(VARIABLE_NAME, NEW_VALUE);

VARIABLE_NAME - a string that specifies an existing global application scope variable (starting with "ga_" prefix) or a system variable. It can be also an array element (for example, "ga_MyArray[3]).

NEW_VALUE - a string that will be assigned as a value to the variable.

 

RunMacro(MACRO_NAME, PARAMETER)

Runs an existing macro. Waits until the macro finishes and returns its result.

var mtwProxy = WScript.CreateObject("Mtw.Proxy");

var result = mtwProxy.RunMacro(MACRO_NAME, PARAMETER);

MACRO_NAME - a string that specifies a name of the existing macro.

PARAMETER - a string that will be passed to the macro as the parameter.

 

 

 

The API parameters and return values are in the UTF-8 encoding. If you use a portable package (you download .zip package and not a .exe installer) then you need to manually register the MtwObj32.dll (32-bit) and MtwObj64.dll (64-bit) in order to make the Mtw.Proxy object work in WScript scripts. The dll's are by default located in c:\Program Files (x86)\Perfect Keyboard\Bin  (or c:\Program Files (x86)\Free Macro Player\Bin).

 

 

Example: 

 

Let's have a macro named "wsTest":

 

<msg>(-100,-100,"wsTest: %_vMacroParameter%","",1,0,0,0)<#>

<varset>("_vMacroResult=Goodbye","")

 

Let's run this JScript:

 

 

function MtwProxySample()

{

          var WSHShell = WScript.CreateObject("WScript.Shell");

              var Mtw = WScript.CreateObject("Mtw.Proxy");

          var result = Mtw.RunMacro("wsTest", "Hello");

          WSHShell.Popup(result);          

}

 

MtwProxySample();

 

 

The macro will be called. It will display a message box with "Hello" text. When the message box is closed text "Goodbye" is showed in the JScript pop up window.