Jump to content
Sign in to follow this  

controlsend sends wrong key

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 "" with "http;//". 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] = ""

$urls[1] = ""

$urls[2] = ""

Dim $urlNames[10]

$urlNames[0] = "c32NLVNV"

$urlNames[1] = "c33NLVNV"

$urlNames[2] = "c63BOIID"

Dim $path = "\\\mrtgTmp\"

Dim $fullPath

Opt("SendKeyDelay", 50)


For $i = 0 to 9 step 1

WinWait("Adobe Acrobat Pro")



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");



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]")



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




;WinWaitClose("Adobe Acrobat Pro", 3)

;sleep( 1000 )



Share this post

Link to post
Share on other sites

Not working. I've tried all the way up to 500ms. It seems to fail in the first iteration of the script. Then, if I manually start it again, its okay. I'm blocked by this. Is there anything else for me to try? Thanks.

Share this post

Link to post
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] = [["", "", ""]["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
$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


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: - 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!"

Share this post

Link to post
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
Sign in to follow this