redeiendre Posted March 26, 2014 Share Posted March 26, 2014 (edited) Hi All, Can you help me to correct my script? So my goal is that I want to send strings with upper case to multiple PUTTY terminal windows. e.g. I have opened two Putty sessions and I would like to send username as "LoGinID" into both Putty windows that's why I need ControlSend function. script: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #Include <Misc.au3> #include <IE.au3> Func megnyit() Opt("WinTitleMatchMode", 2) Global $siteok while 1 $line = FileReadLine($siteok) If @error = -1 Then ExitLoop sleep(40) $array1=StringSplit($line,",",0) If StringInStr($array1[1],"#")=0 then ShellExecute("i:putty.exe ", $array1[1] & " 22 -ssh","","") EndIf WEnd Fileclose($siteok) sleep(100) $siteok=FileOpen(@WorkingDir & "multisites.csv",0) while 1 $line = FileReadLine($siteok) If @error = -1 Then ExitLoop sleep(50) $array1=StringSplit($line,",",0) WinSetTitle($array1[1] & " - PuTTY","",$array1[1]) WEnd Fileclose($siteok) EndFunc Func elkuld() Opt("WinTitleMatchMode", 2) $siteok=FileOpen(@WorkingDir & "multisites.csv",0) Global $command while 1 $line = FileReadLine($siteok) If @error = -1 Then ExitLoop sleep(50) $array1=StringSplit($line,",",0) ControlSend($array1[1],"","",GUICtrlRead($command) & "{ENTER}") WEnd Fileclose($siteok) EndFunc ;~ Now creating the GUI elements GUICreate("Multisite Editor",400,300,-1,-1,$WS_BORDER + $WS_SYSMENU ,'','') $label1=GUICtrlCreateLabel("Enter command:",10,23,100,20) $command=GUICtrlCreateInput("",100,20,130,20) $button=GUICtrlCreateButton("Send command",240,20,100) $button2=GUICtrlCreateButton("Exit",240,80,100) GUISetState(@SW_SHOW) $siteok=FileOpen(@WorkingDir & "multisites.csv",0) If $siteok = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf megnyit() while 1 $msg = GUIGetMsg() Select Case $msg=$button elkuld() Case $msg=$button2 Exit EndSelect WEnd Thanks in advance Edited March 26, 2014 by redeiendre Link to comment Share on other sites More sharing options...
redeiendre Posted March 27, 2014 Author Share Posted March 27, 2014 in the multisites.csv file the IP addresses are listed, so as many PUTTY window will be launched as many records are input Link to comment Share on other sites More sharing options...
JohnOne Posted March 27, 2014 Share Posted March 27, 2014 Perhaps if you posted what it is the same old issue as, it would help someone solve your problem. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
redeiendre Posted March 27, 2014 Author Share Posted March 27, 2014 (edited) I meant that CAPITAL letters cannot be sent with function ControlSend Edited March 27, 2014 by redeiendre Link to comment Share on other sites More sharing options...
redeiendre Posted March 28, 2014 Author Share Posted March 28, 2014 sorted out by the ControlSendPlus: trick was to fill out with a null value the parameter of the $Flag "Func ControlSendPlus($title, $text, $className, $string, $flag)" my code: ControlSend($array1[1],"","",GUICtrlRead($command) & "{ENTER}","") Func ControlSendPlus($title, $text, $className, $string, $flag) ;VERSION 2.0.3 (06/13/2004) Local $ctrl = 0, $alt = 0, $upper, $start, $end, $i, $char, $and, $Chr5Index, $isUpper, $ret If $flag = 2 Or $flag = 3 Then $ctrl = 1 If $flag = 2 Or $flag = 4 Then $alt = 1 If $flag <> 1 Then $flag = 0;set the flag to the default function style $upper = StringSplit('~!@#$%^&*()_+|{}:"<>?ABCDEFGHIJKLMNOPQRSTUVWXYZ', "") If $flag <> 1 Then;don't replace special chars if it's raw mode ;replace {{} and {}} with +[ and +] so they will be displayed properly $string = StringReplace($string, "{{}", "+[") $string = StringReplace($string, "{}}", "+]") ;replace all special chars with Chr(5) ;add the special char to an array. each Chr(5) corresponds with an element Local $Chr5[stringLen($string) / 2 + 1] For $i = 1 To StringLen($string) $start = StringInStr($string, "{") If $start = 0 Then ExitLoop;no more open braces, so no more special chars $end = StringInStr($string, "}") If $end = 0 Then ExitLoop;no more close braces, so no more special chars ;parse inside of braces: $Chr5[$i] = StringMid($string, $start, $end - $start + 1) ;replace with Chr(5) leaving the rest of the string: $string = StringMid($string, 1, $start - 1) & Chr(5) & _ StringMid($string, $end + 1, StringLen($string)) Next ;take out any "!", "^", or "+" characters ;add them to the $Modifiers array to be used durring key sending Local $Modifiers[stringLen($string) + 1] For $i = 1 To StringLen($string) $char = StringMid($string, $i, 1) $and = 0 If $char = "+" Then $and = 1 ElseIf $char = "^" Then $and = 2 ElseIf $char = "!" Then $and = 4 ElseIf $char = "" Then ExitLoop EndIf If $and <> 0 Then $Modifiers[$i] = BitOR($Modifiers[$i], $and) $string = StringMid($string, 1, $i - 1) & _ StringMid($string, $i + 1, StringLen($string)) $i = $i - 1 EndIf Next Else;it is raw mode, so set up an all-0 modifier array Local $Modifiers[stringLen($string) + 1] EndIf ;now send the chars $Chr5Index = 1 For $i = 1 To StringLen($string) $char = StringMid($string, $i, 1) If $char = Chr(5) Then $char = $Chr5[$Chr5Index] $Chr5Index = $Chr5Index + 1 EndIf $isUpper = 0 For $j = 1 To UBound($upper) - 1 If $char == $upper[$j] Then $isUpper = 1 Next ;1 SHIFT, 2 CTRL, 4 ALT (programmer note to keep the bits straight) If $isUpper = 1 Or BitAND($Modifiers[$i], 1) = 1 Then Send("{SHIFTDOWN}") If BitAND($Modifiers[$i], 4) = 4 And Not $alt Then $char = "!" & $char If BitAND($Modifiers[$i], 2) = 2 And Not $ctrl Then $char = "^" & $char If BitAND($Modifiers[$i], 4) = 4 And $alt Then Send("{ALTDOWN}") If BitAND($Modifiers[$i], 2) = 2 And $ctrl Then Send("{CTRLDOWN}") $ret = ControlSend($title, $text, $className, $char, $flag) If BitAND($Modifiers[$i], 4) = 4 And $alt Then Send("{ALTUP}") If BitAND($Modifiers[$i], 2) = 2 And $ctrl Then Send("{CTRLUP}") If $isUpper = 1 Or BitAND($Modifiers[$i], 1) = 1 Then Send("{SHIFTUP}") If Not $ret Then Return 0;window or control not found Next Return 1 EndFunc ;==>ControlSendPlus Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now