VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   How to set a key map option in script? (https://forums.vandyke.com/showthread.php?t=13930)

seesea 10-10-2019 11:46 PM

How to set a key map option in script?
 
1 Attachment(s)
Hello,I wanted to set a key map in script, but failed, will anyone can help me? Thank you!
Bellow is the option's screen shot, I'd like to set it in script:
https://forums.vandyke.com/attachmen...1&d=1570784783

My Securecrt version is: Version 7.1.3 (build 378).

The help file says: If the option is a multi-string (Z), an array of strings should be specified for the value.
I get the property text from an ini file like below:
Code:

---------------------------
Z:"Keymap v3"=00000001
 C        VK_C                        DISABLED
---------------------------

But I failed using both the two codes:
Code:

crt.Session.Config.SetOption("Keymap v3", new Array("C        VK_C                        DISABLED"));
crt.Session.Config.SetOption("Keymap v3", "C        VK_C                        DISABLED");

CRT showed me the error message dialog:
Code:

---------------------------
SecureCRT
---------------------------
CRT Scripting Runtime error

Error: The specified value is not valid for 'Keymap v3'.

I tested the type of the option of which session has the key map value setted, only showed that is an object, not an array:
session.ini:
Code:

Z:"Keymap v3"=00000001
 C        VK_C                        DISABLED

js:
Code:

# $language = "JScript"
# $interface = "1.0"

function alert(strContent, strTitle)
{
    crt.dialog.MessageBox(strContent, strTitle);
}

function main()
{
    alert(crt.Session.Config.GetOption("Keymap v3").toString());                        // [object Object]
    alert(Object.prototype.toString.call(crt.Session.Config.GetOption("Keymap v3")));  // [object Object]
    alert(crt.Session.Config.GetOption("Keymap v3") instanceof Object);                // False
    alert(crt.Session.Config.GetOption("Keymap v3") instanceof Array);                  // False

    var keys =[];
    testObj=crt.Session.Config.GetOption("Keymap v3");
  for(var i in testObj){
      keys.push(i);
  }
    alert(keys.join("-"));      // "" Empty string
}

When I tested in python, it showed that is a list, but no value:
Code:

# $language = "Python"
# $interface = "1.0"

obj=crt.Session.Config.GetOption("Keymap v3")
crt.Dialog.MessageBox('\n'.join(obj))    // ""
crt.Dialog.MessageBox(type(obj).__name__) // list


ashiosee 10-11-2019 12:19 PM

SecureCRT version 7.1.3 has not been in active development since December, 2013.

What behavior do you experience if you use the current version of SecureCRT?

seesea 10-12-2019 12:37 AM

Hi Allen,
Thank you for your reply, I can't test this in the latest version because we are not allowed to install that in our office's pc.
Since the help file is match the version, I think the script in the help should work on this SecureCRT, and I tested the SetOption in vbs, python and js, I found out that js not work only, but it is sure that js script can get the option object, what a pity I don't know how to operate it.
Is that js is not recommended and is not supported well in CRT scripting? I prefer to use js because all of the scripts in our department are js, it is a big project to change.

Bellow is my test:
1. vbs works:
Code:

# $language = "VBScript"
# $interface = "1.0"

Set objTab = crt.GetScriptTab
Set objConfig = objTab.Session.Config
objConfig.SetOption "Keymap v3", Array("C        VK_C                        DISABLED")
strValue = Join(objConfig.GetOption("Keymap v3"), vbcrlf)
crt.Dialog.MessageBox strValue

2. python works:
Code:

# $language = "python"
# $interface = "1.0"

objTab = crt.GetScriptTab()
objConfig = objTab.Session.Config
arrNewValue = []
arrNewValue.append(" C        VK_C                        DISABLED")
objConfig.SetOption("Keymap v3", arrNewValue)
arrValue = objConfig.GetOption("Keymap v3")
strValue = ''.join(arrValue)
crt.Dialog.MessageBox(strValue)

3. js not works:
Code:

# $language = "JScript"
# $interface = "1.0"

objTab = crt.GetScriptTab();
objConfig = objTab.Session.Config;
// ar = ["C        VK_C                        DISABLED"];
ar = new Array("C        VK_C                        DISABLED");
objConfig.SetOption("Keymap v3", ar);
strValue = objConfig.GetOption("Keymap v3").join(", ");
crt.Dialog.messageBox(strValue);

The error message is:
Code:

---------------------------
SecureCRT
---------------------------
CRT Scripting Runtime error
Error: The specified value is not valid for 'Keymap v3'.


ashiosee 10-14-2019 11:40 AM

Quote:

Originally Posted by seesea (Post 52438)
I found out that js not work only, but it is sure that js script can get the option object, what a pity I don't know how to operate it. Is that js is not recommended and is not supported well in CRT scripting? I prefer to use js because all of the scripts in our department are js, it is a big project to change.

Arrays in JS are objects, and cannot be converted into an array that is compatible with the ActiveX Variant that the scripting API in SecureCRT requires.

I will capture a feature request for the ability to support jscript arrays in SecureCRT's scripting API, but since you're not going to be able to upgrade even if this feature becomes available, you're stuck with using VBScript or Python.

seesea 10-14-2019 08:19 PM

Hi Allen,
Thank you for your infomation, then I know that I should look for another way to get this function, maybe I can try set the option by loading an ini file or sth else.
Thanks again Allen.


All times are GMT -6. The time now is 10:41 AM.