VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   SecureCRT to SendKeys with Python (https://forums.vandyke.com/showthread.php?t=13386)

Caiser 02-02-2019 04:10 AM

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.

ekoranyi 02-03-2019 10:05 AM

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?

Caiser 02-05-2019 07:52 PM

What about other keys, for exmple, alt/alt+crt?
 
Is there a list of chr(1) to chr(n) which represent the keys?

ekoranyi 02-06-2019 09:44 AM

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.

Caiser 02-12-2019 05:27 AM

Thanks, it really works.
 
Thanks, it really works.:)


All times are GMT -6. The time now is 01:38 AM.