Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-02-2019, 03:10 AM
Caiser Caiser is offline
Registered User
 
Join Date: Aug 2015
Posts: 4
SecureCRT to SendKeys with Python

As checked the help file , with python, can not send a key to the screen.

I am using python2.7.15.
What can I alternatively do to send the ^C(which is supposed to be CTRL+C) to the screen with python?


SendKeys
Description
Sends key strokes to the active window.
Remarks
The SendKeys method can send more than one keystroke at a time by using compound string arguments. For example, to send the keystrokes a, b, and c, you would send the string argument "abc". The SendKeys method also uses some characters as modifiers of characters. This set of special characters consists of the plus sign (+), caret (^), percent sign (%), tilde (~), parentheses, brackets, and braces. The characters "+", "^", and "%" perform the functions of SHIFT, CTRL, and ALT, respectively. These can be combined to affect one key as in "^%c" which is the equivalent of the CTRL+ALT+C key combination. Parenthesis characters are used to group characters for modifiers, for example, "+(ec)" will send "EC". SendKeys can use up to three nested parenthesis.

To send bracket characters, send the string argument "{[}" for the left bracket and "{]}" for the right one. To send brace characters, send the string argument "{{}" for the left brace and "{}}" for the right one.

Some keystrokes do not generate characters (such as ENTER and TAB). Some keystrokes represent actions (such as BACKSPACE and BREAK). To send these kinds of keystrokes, send the arguments shown in the SendKeys keystroke table.
VBScript
Syntax
object.SendKeys string
Example
#$language = "VBScript"
#$interface = "1.0"
Sub Main()
crt.Screen.Clear
crt.screen.sendkeys("mc~")
crt.Sleep 2000
crt.screen.sendkeys("{f1}")
crt.Sleep 2000
crt.screen.sendkeys("{esc}0")
crt.Sleep 2000
crt.screen.sendkeys("{esc}0")
crt.Sleep 2000
crt.screen.sendkeys("y")
End Sub
Python
Syntax
SendKeys is not currently supported for Python.
Reply With Quote
  #2  
Old 02-03-2019, 09:05 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi Caiser,

One method of sending a CTRL+C to the remote system to use crt.Screen.Send.
Code:
crt.Screen.Send(chr(3))
Does this provide the behavior you're looking for?
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 02-05-2019, 06:52 PM
Caiser Caiser is offline
Registered User
 
Join Date: Aug 2015
Posts: 4
Thumbs up What about other keys, for exmple, alt/alt+crt?

Is there a list of chr(1) to chr(n) which represent the keys?
Reply With Quote
  #4  
Old 02-06-2019, 08:44 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi Caiser,

These are not specific to SecureCRT, this is a built in function of Python.

The Python Documentation describes it as:
chr(i)
Return a string of one character whose ASCII code is the integer i. For example, chr(97) returns the string 'a'. This is the inverse of ord(). The argument must be in the range [0..255], inclusive; ValueError will be raised if i is outside that range. See also unichr().
A quick search for ASCII Control Codes should result in several lists of the ASCII equivalent of common control codes.
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 02-12-2019, 04:27 AM
Caiser Caiser is offline
Registered User
 
Join Date: Aug 2015
Posts: 4
Thanks, it really works.

Thanks, it really works.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 05:19 PM.