Issue with ControlSend function using AutoIT in Ruby

I’m having an issue running scripts that use AutoIT against my windows
box, half the time the ControlSend function sends a string to the GUI
that should be all upcase, in a hodge-podge of different case letters.

Example:

I’m trying to send a string to a window with the following variables,
ext.
(this isn’t the actual code, just the pertinent bits)

@datestring = date.year.to_s + “" + date.month.to_s + "” +
date.day.to_s
@hostname = hostname
@hostname = @hostname.upcase.to_s.chomp

autoit = WIN32OLE.new(“AutoItX3.Control”)
autoit.ControlSend(“Enter SQL Database Information”, “”, 302,
“LMNIGHTLY#{@hostname}#{@datestring}”)

Most of the time this will send a string like
“LMNIGHTLYHOSTNAME2007_5_25” but occasionally it sends a string like
“lMNIgHTlyHOsTNAME2007_5_2”.

At other places in the script it has the send the same string to a
system call, and this always comes out correctly, so it seems like it’s
just a problem with AutoIT.

Also the issue seems specific to some aspect of my windows configuration
because the script runs fine on some servers and not on others.

Has anyone had experience with this issue before?

On May 25, 1:51 pm, Skye Weir-Mathews [email protected] wrote:
…SNIP…

Most of the time this will send a string like
“LMNIGHTLYHOSTNAME2007_5_25” but occasionally it sends a string like
“lMNIgHTlyHOsTNAME2007_5_2”.

At other places in the script it has the send the same string to a
system call, and this always comes out correctly, so it seems like it’s
just a problem with AutoIT.
…SNIP…

The AutoItX docs indicate the the Send command is sensitive to the
state of Caps L.
and also can be affected is a user happens to be holding down SHIFT
when the command
is executed. Would explain the intermittent/seemingly system dependent
behavior…

Cheers
Chris H.

ChrisH wrote:

The AutoItX docs indicate the the Send command is sensitive to the
state of Caps L.
and also can be affected is a user happens to be holding down SHIFT
when the command
is executed. Would explain the intermittent/seemingly system dependent
behavior…

Cheers
Chris H.

This worked well at first, but then my issue came back which is
confusing to me, because I’ve run a number of tests making absolutely
sure that Caps L. is turned off and I wasn’t touching the keyboard at
all. Interestingly enough when AutoIT send a bad string, it always
downcases the same letters (when “LMNIGHTLYHOSTNAME2007_5_25” is bad, it
always looks like “lMNIgHTlyHOsTNAME2007_5_2”) which makes me think that
it’s not related to input from the keyboard, which is likely to be
different every time.

Okay, I think I figured it out, my script was automating an installer
and sending messages to STDOUT letting me know how it was progressing
through the installation

for example:

puts “Enter Microsoft SQL Database Authentication Information”

autoit.WinWait(“Enter Microsoft SQL Database Authentication
Information”, “”, 5)

autoit.ControlSend(“Enter Microsoft SQL Database Authentication
Information”, “”, 301, “XXX”)

autoit.ControlSend(“Enter Microsoft SQL Database Authentication
Information”, “”, 302, “XXX”)

autoit.ControlSend(“Enter Microsoft SQL Database Authentication
Information”, “”, 1, “{ENTER}”)

so, I noticed that when the script was running in the background it
installed fine, and when it was running in the foreground I got the
funky chars. Since then I commented out the lines like puts “Enter
Microsoft SQL Database Authentication Information” and it seems to be
running fine.

Thanks ya’ll

On 5/29/07, Skye Weir-Mathews [email protected] wrote:

This worked well at first, but then my issue came back which is
confusing to me, because I’ve run a number of tests making absolutely
sure that Caps L. is turned off and I wasn’t touching the keyboard at
all. Interestingly enough when AutoIT send a bad string, it always
downcases the same letters (when “LMNIGHTLYHOSTNAME2007_5_25” is bad, it
always looks like “lMNIgHTlyHOsTNAME2007_5_2”) which makes me think that
it’s not related to input from the keyboard, which is likely to be
different every time.

This seems to be an issue with autoit itself. At first I intended to
ask you to try with standalone autoit, but then I googled a bit, and
found [1]. So look at autoit site if there’s a solution. I’m too
sleepy to do anything more now.

Jano

[1] Case problem in ControlSend() - AutoIt General Help and Support - AutoIt Forums

Just in case anyone else finds this post looking for resolution with
this issue, redirecting STDOUT didn’t actually fix anything. What really
worked was changing the parts where I was sending text to the screen
from using the ControlSend function to using ControlSetText. Now my
script looks like this and seems to be working great.

puts “Enter SQL Database Information”
autoit.WinWait(“Enter SQL Database Information”, “”, 5)
autoit.ControlSetText(“Enter SQL Database Information”, “”, 301,
“#{@dbserver}”)
autoit.ControlSetText(“Enter SQL Database Information”, “”, 302,
“LMNIGHTLY#{@hostname}#{@datestring}”)
autoit.ControlSend(“Enter SQL Database Information”, “”, 1,
“{ENTER}”)