Jump to content

controlsend sends wrong key


darkwalk
 Share

Recommended Posts

I have the following script that opens acrobat pro and makes pdf from webpages. It works 80% of the time. The rest, however, does not. The "ControlSend" command sometimes will replace "http://66.82.3.80" with "http;//66.82.3.80". Notice the ";". Also, once in a blue moon, it will replace the numbers "32" with "#@". It looks like the shift key was depressed, but I don't touch the keyboard when the script is running. Any help is appreciated. Thanks!

Dim $urls[10]

$urls[0] = "http://66.82.3.80"

$urls[1] = "http://66.82.3.80"

$urls[2] = "http://66.82.3.73"

Dim $urlNames[10]

$urlNames[0] = "c32NLVNV"

$urlNames[1] = "c33NLVNV"

$urlNames[2] = "c63BOIID"

Dim $path = "\\127.0.0.1\mrtgTmp\"

Dim $fullPath

Opt("SendKeyDelay", 50)

ShellExecute("Acrobat.exe")

For $i = 0 to 9 step 1

WinWait("Adobe Acrobat Pro")

sleep(2000)

Send("+^o")

WinWait("Create PDF from Web Page")

ControlSend("Create PDF from Web Page", "", "", $urls[$i]) ************** Problem area ***********************

ControlClick ( "Create PDF from Web Page", "", "[CLASS:Button; INSTANCE:8]")

WinWait("Download Status");

WinWaitClose("Download Status");

sleep(200)

Send("+^s")

WinWait("Save As")

$fullPath = $path & $urlNames[$i] & ".pdf" ************** Problem area ***********************

ControlFocus("Save As", "", 1148 )

ControlSend("Save As","","",$fullPath)

ControlClick("Save As","","[CLASS:Button; INSTANCE:2]")

sleep(100)

Send("!y")

WinWait($urlNames[$i] & ".pdf","",2)

sleep(200)

Send("^w")

sleep(200)

;WinWaitClose("Adobe Acrobat Pro", 3)

;sleep( 1000 )

Next

Send("^q")

Link to comment
Share on other sites

A couple of tips to get you started with controls and arrays

  • Always set the ControlID parameter instead of using an empty string
  • Try ControlSetText() instead of ControlSend()
  • Try Not to use Dim and definitly don't use it to declare a non-array variable. Dim = Dim(ension) Use Global or Local instead
  • Create your Arrays as a single 2-Dimension array instead (See Below)
  • You don't need the Step 1. That's the default. Just use For $i = 0 to Ubound(<array>) -1

This is just off the top of my head so double-check it against the help file.

Global $aURL[3][2] = [["http://66.82.3.80", "http://66.82.3.80", "http://66.82.3.73"]["c32NLVNV", "c33NLVNV", "c63BOIID"]] ;; Watch out for line wrap

;;To Call the Array Elements your lines would change to
ControlSetText("Create PDF from Web Page", "", <controlID>, $aURL[$i][0]);; ************** Problem area
;;And
$fullPath = $path & $aURL[$i][1] & ".pdf";; ************** Problem area

Edit: Oooops, forgot one. If you are going to use ControlSend() anyway, set the flag to 1 (raw) in case there are "special" characters in the string.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...