Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-10-2019, 11:46 PM
seesea's Avatar
seesea seesea is offline
Registered User
 
Join Date: Jun 2010
Posts: 20
Question How to set a key map option in script?

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:


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
Attached Images
File Type: jpg keymap.jpg (32.8 KB, 3150 views)

Last edited by seesea; 10-11-2019 at 03:12 AM.
Reply With Quote
  #2  
Old 10-11-2019, 12:19 PM
ashiosee ashiosee is offline
Registered User
 
Join Date: Oct 2019
Posts: 24
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?
__________________
--Allen

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 10-12-2019, 12:37 AM
seesea's Avatar
seesea seesea is offline
Registered User
 
Join Date: Jun 2010
Posts: 20
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'.

Last edited by seesea; 10-12-2019 at 12:41 AM.
Reply With Quote
  #4  
Old 10-14-2019, 11:40 AM
ashiosee ashiosee is offline
Registered User
 
Join Date: Oct 2019
Posts: 24
Quote:
Originally Posted by seesea View Post
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.
__________________
--Allen

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 10-14-2019, 08:19 PM
seesea's Avatar
seesea seesea is offline
Registered User
 
Join Date: Jun 2010
Posts: 20
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.
Reply With Quote
Reply

Tags
keymap , script , securecrt

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 08:46 AM.