Jump to content

ControlSend - Odd behaviour..sometimes


Recommended Posts

Hi,

I kept meaning to post this odd behaviour problem with the ControlSend function before but never got around.

Sometimes, when I send text to a control using ControlSend I get the character that would be generated if the Shift key was pressed or not. For example, just now I sent an address string "80 Streetname" and it posted "8) Streetname". One of my other scripts sends a file path/filname and again the odd time instead of sending "M:\Folder" I get "M;\Folder". I've tried increasing the delay to 500ms and that hasn't really done much. Is there something else that I am missing or can do?

Thanks

Link to comment
Share on other sites

  • 2 weeks later...

I get this same behavior with some of the automation scripts I have created that use ControlSend. I can always replicate the issue if I run a script on a computer that doesn't have autoit installed and the script is being run for the first time on that computer. If I run the compiled script a second time it seems to send the text just fine.

I also tried to get around the issue by using ControlSetText where I could. In the instances where ControlSend would not work as intended the ControlSetText would not work at all leaving the Edit box blank.

I would also like to know if there is any known fix or work around for this.

Link to comment
Share on other sites

Hi,

I kept meaning to post this odd behaviour problem with the ControlSend function before but never got around.

Sometimes, when I send text to a control using ControlSend I get the character that would be generated if the Shift key was pressed or not. For example, just now I sent an address string "80 Streetname" and it posted "8) Streetname". One of my other scripts sends a file path/filname and again the odd time instead of sending "M:\Folder" I get "M;\Folder". I've tried increasing the delay to 500ms and that hasn't really done much. Is there something else that I am missing or can do?

Thanks

I have had the exact same problem with the SHIFT function randomly activating. The only thing I have done to fix this is to set the

Opt("SendKeyDelay") to something very high, liek Opt("SendKeyDelay", 50). The downside to this work around is that you're program will now type substantially slower...

It'd be nice if the function just worked. Since it's so repeatable, I'm guessing a Dev or someone has commented on this? I've searched for ControlSend and I can't seem to find anything.

Link to comment
Share on other sites

The only problem where other program is starting to mess with chars happend to me when i tryed to send alot of data to other program fastest i can, basicly script finished with sending but program whas still trying to katchup and as a result, program mesed alot of chars and broked accepting the data around line 800-1200

Basicly autoit is sending them correct, the problem is in the speed with program that is trying to accept data.

Did you try to see if itl work with

ControlCommand("Untitled -", "", "Edit1", "EditPaste", "string")

You can try with ClipPut

And when you got confirmation from ClipGet (that ClipGet = data that you ClipPuted) ControlSend "^v" or something similar to see if itl work better.

You can compare data after sending ControlGetText and if its not identical then resend it

Note that your win probably shud b active

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

  • 2 months later...

This topic explains a problem I've been having for the last month. I'm trying to use AutoIt as an automated test system for our development work.

I spotted a problem, so developed this script to test it:

#cs ----------------------------------------------------------------------------
  Tests the response of a TEdit Character map field to AutoIt.

  Toytown programming: no error handling.
  This version is GUILess. We need to do two things:
  1. Put in lockout via BlockInput to stop effects of mouse moves
    and clicks. This needs #RequireAdmin.
  2. Have the PauseMakeSureWindowIsReady routines to delay the
    write to and read from the control.
#ce ----------------------------------------------------------------------------
#RequireAdmin

Global $iLineCount = 0 ; Always updated by the OutputLogLine routine
Global $iErrorCount = 0 ; Always updated by any test routine

;Open log file, write first line
Global $fLogFile = FileOpen(@ScriptDir & "\TestCharMapLogFile.txt", 2)
OutputLogLine("Started UAT Test Char Map at " & GetNow(), 1)

;Start test executable
Run(@SystemDir & "\charmap.exe")
Global $hWHandle = WinWaitActive("Character Map", "", 2)

BlockInput(1)

;Run test xx times checking input into field
For $iI = 1 To 10000
  $sPasswordText1 = "ufVNn{{"""
  SendTextToControl($sPasswordText1)
  OutputLogLine("Password field given password =>" & $sPasswordText1 & "<=")
  CheckTextFromControl($sPasswordText1)
  OutputBlankLine()
Next

BlockInput(0)

;Write last line, close out log file
OutputLogLine("Run completed at: " & GetNow() & " with " & $iErrorCount & " errors.")
  FileClose($fLogFile)
Exit

;Send text string to control
Func SendTextToControl(Const $sText)
  Local $iSendTextCharRaw = 1
  PauseMakeSureWindowIsReady()
  ControlFocus("", "", "[CLASS:RICHEDIT50W; INSTANCE:1]")
  ControlSend("", "", "[CLASS:RICHEDIT50W; INSTANCE:1]", "{HOME}+{END}{DEL}")
  PauseMakeSureWindowIsReady()
  ControlSend("", "", "[CLASS:RICHEDIT50W; INSTANCE:1]", $sText, $iSendTextCharRaw)
EndFunc

;Check that control has test text string
Func CheckTextFromControl(Const $sText)
  PauseMakeSureWindowIsReady()
  Local $sCheckText = ControlGetText("", "", "[CLASS:RICHEDIT50W; INSTANCE:1]")
  If $sCheckText == $sText Then
    OutputLogLine("Text in " & "[CLASS:RICHEDIT50W; INSTANCE:1]" & " is =>" & $sCheckText & "<= and is correct.")
  Else
    OutputLogLine("Text in " & "[CLASS:RICHEDIT50W; INSTANCE:1]" & " is =>" & $sCheckText & "<= and is INCORRECT. +++ERROR+++")
    $iErrorCount += 1
  EndIf
EndFunc

;Make sure our windows's active with pause
Func PauseMakeSureWindowIsReady()
  Do
    Sleep(500)
  Until WinActive("Character Map")
EndFunc

;Output line to log file, with trailing blank lines if required
Func OutputLogLine(Const $sOutLine, Const $iExLines = 0)
  $iLineCount += 1
  $sOutput = StringFormat("%06u", $iLineCount) & " " & $sOutLine
  FileWriteLine($fLogFile, $sOutput)
  For $iCount = 1 To $iExLines
    FileWriteLine($fLogFile, @CRLF)
  Next
EndFunc

;Output blank line to log file
Func OutputBlankLine()
  FileWriteLine($fLogFile, @CRLF)
EndFunc

;Get formatted date and time ISO 8601
Func GetNow()
return @YEAR & "-" & @MON & "-" & @MDAY & "T" & @HOUR & ":" & @MIN & ":" & @SEC
EndFunc

Basically, the script does:

1. Opens a log file.

2. Brings up the character map (which has a field one can enter text in).

3. Blocks all input to stop inputs interfering.

4. Goes into a loop where it clears the field, fires a bit of text into it, and then reads it back. There are at least 500ms pauses between each step, and what's sent in and read back is logged.

5. Unblocks input.

6. Closes out the log file and exits.

If I run the loop 10,000 times, almost always the input will match what's read. But maybe once or twice in the 10,000 times I get this in the log file:

000150 Password field given password =>ufVNn{{"<=

000151 Text in [CLASS:RICHEDIT50W; INSTANCE:1] is =>ufVNn[{2<= and is INCORRECT. +++ERROR+++

Note the actual string I'm using is

ufVNn{{"

- the "arrows" are delimiters in the log.

In this example, one of the "{" has been cap-shifted to "[", and the final quote has been down-shifted to "2". The actual shifted characters can change, and the shift can be in either direction. The frequency this happens isn't high (and seems to be machine-dependent), but I'd say it averages a couple of times per 10,000.

It would seem odd if it were timing, as 500ms pauses are a long time for an Intel Quad Core X9650 running at 3.7GHz which isn't doing anything else especially.

Does anybody have any other ideas? This is a problem for us as running an automated test 10,000 times is by no means unusual.

Thanks,

Prune

Link to comment
Share on other sites

  • 2 weeks later...

Same problem. It will type, "ACCESSORIES THAT ARE ON dELETE STATUS" and things like that. Unfortunately ControlSetText will not work on the program I'm dealing with...

I've tried adjusting SendKeyDelay, SendCapslockMode, and the special characters/raw mode for ControlSend but have not found a consistently reliable setup yet.

Link to comment
Share on other sites

If I may add my input...

I use tons of automation in my job and have seen this problem a lot. The way I work around it and get 99% reliable results...

Most often this happens in the same place in the script (just sometimes it happens, sometimes it doesn't)

So what I do is I end the send command right before the mess up point

Add a small sleep

then send the rest of the line (or up to the next point it messes up)

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

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...