Page 1 of 1 1
Topic Options
#165046 - 2006-07-25 11:04 PM SendKey problem
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Okay I can't see what I am doing wrong with the following code....

The issue is in the Send() Function, it does the "config t" just fine and sends all the the {enter} keys, but not the $checkstring. It ends up on the console.

Any ideas what my simple brain is overlooking today?

Code:

;Script Options
$SO=SETOPTION("Explicit", "ON")
$SO=SETOPTION("NoMacrosInStrings", "ON")
$SO=SETOPTION("NoVarsInStrings", "ON")
$SO=SETOPTION("WrapAtEOL", "ON")
BREAK ON
Dim $SO, $FH, $Device[], $Input[], $R, $, $I
   
CLS
$FH=FreeFileHandle()

If Open($FH, @ScriptDir+"\devicelist.txt",2)= 0
   
$R = Readline($fh)
   
$SO = 0
   
While @Error = 0
       
Redim Preserve $Device[$SO]
       
$Device[$SO] = $R
        $SO = $SO + 1
       
$R = Readline($fh)
   
Loop
    Close($FH)
Else
    ? @Serror
EndIF

If Open($FH, @ScriptDir+"\input.txt",2)=0    
    $R = Readline($fh)
   
$SO = 0
   
While @Error = 0
       
Redim Preserve $Input[$SO]
       
$Input[$SO] = $R
        $SO = $SO + 1
       
$R = Readline($fh)
   
Loop
    Close($FH)
Else
    ? @Serror    
EndIF

For each $SO in $Device
    CLS
    ? "Please connect to: " + $SO
    ? "Press -C- once connected and in Exec mode"
    Press()
   
Select
        Case SetFocus("Untitled - Notepad") = 0
           
$I = "Untitled - Notepad"
        Case Setfocus("Telnet "+$SO) = 0
           
$I = "Telnet "+$SO
        Case Setfocus($SO+" - PuTTY") = 0
           
$I = $SO + " - PuTTY"
        Case Setfocus($SO+" - SecureCRT") = 0
           
$I = $SO + " - SecureCRT"
        Case ? "Unable to find Window"
            $I = 0
   
EndSelect
If
$I <> 0
    Send(
$Input,$I)
EndIf

Next


Function Press()
Dim $

While $ <> "C"
    Get $
Loop

EndFunction

Function Send($Input,$I)
Dim $, $Checkstring
SetFocus($I)
Sendkeys("config t {enter}")
   
For each $ in $Input
        CheckString($)
       
SetFocus($I)
       
SendKeys($checkstring+"{Enter}")
   
Next
EndFunction


Function CheckString ($letters)
Dim $a, $i, $s
$a = ""
For $i= 1 to Len($letters)
$a = Substr($letters, $i, 1)
   
Select
        Case $a = "+"
        $a = "{+}"
        Case $a = "^"
        $a = "{^}"
        Case $a = "~"
        $a = "{~}"
        Case $a = "("
        $a = "{(}"
        Case $a = ")"
        $a = "{)}"
        Case $a = "{"
        $a = "{{}"
        Case $a = "}"
        $a = "{}}"
    EndSelect
$s = $s+$a
Next
$checkstring = $s
EndFunction


_________________________
Today is the tomorrow you worried about yesterday.

Top
#165047 - 2006-07-25 11:28 PM Re: SendKey problem
DrillSergeant Offline
MM club member
*****

Registered: 2004-07-09
Posts: 1164
Loc: Eijsden, the Netherlands
I think you've found a bug here:
Code:

Run("Notepad.exe")
Sleep(1)
SetFocus("Untitled – Notepad")

$ReturnCode = SendKeys("{{}test{}}")



does not return {test} (as the manual says it should) but it returns {test}}

can anyone confirm be4 we report this as a bug?

Top
#165048 - 2006-07-25 11:52 PM Re: SendKey problem
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
don't know about it being a bug as the console output looks correct to me, the issue is that for testing I am setting focus to Untitled - Notepad, and it is sending the $CheckString variable to the console and not the notepad. However the {enter} portion of the SendKeys statement is working.
Top
#165049 - 2006-07-26 01:53 AM Re: SendKey problem
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Instead of concatenating with +, try using two lines of SendKeys().
Top
#165050 - 2006-07-26 02:08 AM Re: SendKey problem
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Ok changed it per Les's suggestion
Code:
Function Send($Input,$I)
Dim $, $Checkstring
SetFocus($I)
Sendkeys("config t {enter}")
   
For each $ in $Input
        CheckString($)
       
SetFocus($I)
       
SendKeys($checkstring)
       
SendKeys("{Enter}")
   
Next
EndFunction



Had the same effect.

Here is the text file that I am reading into the array
Code:

banner motd ~c
********************************Warning Notice*********************************
| |
| This system is restricted solely to AHCCCS authorized users for legitimate |
| purposes only. The State of Arizona strictly prohibits the actual or |
| attempted unauthorized access, use or modification of this system. |
| Unauthorized usage and/or users are subject to disciplinary proceedings |
| and/or criminal and civil penalties under State and Federal law. The use of |
| this system may be monitored and recorded for administrative and security |
| reasons. Anyone accessing this system expressly consents to such monitoring |
| and is advised that if monitoring reveals possible evidence of criminal |
| activity, the State of Arizona may provide the evidence of such activity to |
| law enforcement officials. All authorized users who have access to AHCCCS |
| computer systems and data are bound by applicable laws, rules and AHCCCS |
| directives, including but not limited to, AHCCCS Administrative Policies |
| and Procedures, AHCCCS Privacy and Security Policies, ARS 41-770, and |
| ARS 38-448. |
-------------------------------------------------------------------------------
*****Unauthorized access may be subject to prosecution under ARS 13-2316.******
~c


Top
#165051 - 2006-07-26 11:08 AM Re: SendKey problem
DrillSergeant Offline
MM club member
*****

Registered: 2004-07-09
Posts: 1164
Loc: Eijsden, the Netherlands
-k-
If I do this:
Code:
Break On Cls

Run("Notepad.exe")
Sleep(1)
$dum = SetFocus("Untitled – Notepad")

$text = "asdf","asdfa","asdfasdf","adfasfd"
$scr = "Untitled – Notepad"

$dum = Send($text, $scr)

Function Send($Input,$I)
Dim $, $Checkstring
$dum = SetFocus($I)
;Sendkeys("config t {enter}")
For each $ in $Input
;$test = CheckString($)
$dum = SetFocus($I)
$dum = SendKeys($+"{ENTER}")
Next
EndFunction

Function CheckString ($letters)
Dim $a, $i, $s
$a = ""
For $i= 1 to Len($letters)
$a = Substr($letters, $i, 1)
Select
Case $a = "+"
$a = "{+}"
Case $a = "^"
$a = "{^}"
Case $a = "~"
$a = "{~}"
Case $a = "("
$a = "{(}"
Case $a = ")"
$a = "{)}"
Case $a = "{"
$a = "{{}"
Case $a = "}"
$a = "{}}"
EndSelect
$s = $s+$a
Next
$checkstring = $s
EndFunction



with version 4.51 I get:

Code:

asdf
asdfa
asdfasdf
adfasfd


in notepad

with v4.52 i get:
Code:

asdfEasdfaEasdfasdfEadfasfdE



so there's something broken...

for you, this:
CheckString($)

echos the result of checkstring to the console. You want:

$test = checkstring($)
sendkeys($test)

or

sendkeys(checkstring($))

(which is golf code )

Top
#165052 - 2006-07-26 02:22 PM Re: SendKey problem
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
I like this solution
Quote:

sendkeys(checkstring($))



I am out of the office today so will have to wait till tomorrow for testing, but thanks for the help.

Top
#165053 - 2006-07-27 08:43 PM Re: SendKey problem
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Just to follow up and say that the opted solution worked as expected.
Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.11 seconds in which 0.077 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org