Sign in to follow this  
Followers 0
AutID

ControlSend/Send not working accurately

8 posts in this topic

#1 ·  Posted (edited)

So I am having this bug, don't know if someone had that before, couldn't find much with google and forum searches.

I want to send TAB to a specific window we have at work. Tab changes the value of some specific things on the window.
Now the first way I tried is ControlSend($hWND, "", "", "{TAB}"). That would normally work but in my case, it doesn't. I tried elevating scite, even though our program doesn't require admin, but still nothing. ControlSend doesn't return any error.
Then the second bad way I tried was

WinActivate($hWND)

Send("{TAB}").
Now this works once out of ten. I could run the same script 10 times and it will only work once, maybe less. 1/20 times.

I don't have any clue from which side this bug is coming from, autoit or my window.

 

Any ideas?

Edited by AutID

Share this post


Link to post
Share on other sites



Why are you using the WindowHandle in the ControlHandle parameter of ControlSend()?

Jos

Sorry about that, wrote it by hand, didn't check it in scite. I have used those commands very little in autoit. Not very big fan of those commands :/. Will edit the post.

Share this post


Link to post
Share on other sites

No clue what you are telling me there.  Just Cut&Paste what you have in your script into a codebox.
The ControlSend() now only contains a WindowHandle. You are missing the control you want to send the TAB to.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

OT:

"ControlSend/Send not working accurately" is definitely not true! With this title you insinuate that the AutoIt-developers are lazy dumbasses not fixing a "bug" since years! They are NOT!

"I am not able to understand how ControlSend/Send works accurately" should be the title! 

 

BTT:

After activating a Window it is highly recommended to wait until the activation of this Window! In your example the Send("{TAB}") is executed immediately after the WinActivate($hWND)! At this time, Windows is processing the activation of the window, and nobody knows if the window is active or not. You have to ensure that the Window is active, maybe "WinWaitActive" would good to start with....

Edited by AndyG

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

No clue what you are telling me there.  Just Cut&Paste what you have in your script into a codebox.
The ControlSend() now only contains a WindowHandle. You are missing the control you want to send the TAB to.

Jos

 

The controlID doesn't have to be specified if the control has focus when the windows is activated, cases sensitive excluded.
This example will work as the original one in the examples provided from autoit(controlID not included)

Example()


Func Example()
 ; Run Notepad
 Run("notepad.exe")


 ; Wait 10 seconds for the Notepad window to appear.
 Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)

 ; Wait for 2 seconds.
 Sleep(2000)

 ; Send a string of text to the edit control of Notepad. The handle returned by WinWait is used for the "title" parameter of ControlSend.
 ControlSend($hWnd, "", "", "This is some text")

 ; Wait for 2 seconds.
 Sleep(2000)

 ; Close the Notepad window using the handle returned by WinWait.
 WinClose($hWnd)

 ; Now a screen will pop up and ask to save the changes, the classname of the window is called
 ; "#32770" and simulating the "TAB" key to move to the second button in which the "ENTER" is simulated to not "save the file"
 WinWaitActive("[CLASS:#32770]")
 Sleep(500)
 Send("{TAB}{ENTER}")
EndFunc   ;==>Example

 

 In my case when the window is activated, my control has focus.
Now after this simpe code:

Local $hWND = WinGetHandle("title")


Sleep(3000) ;so the guy from the 5th post won't compain
ControlSend($hWND, "", "", "{TAB}")

if I simply press TAB on my keyboard, it will work like a charm. However if I add more sleep and then use Send("{TAB}") it won't work.

 

Anyway Jos this is just an explanation, no worries I found a workaround.

Edited by AutID

Share this post


Link to post
Share on other sites

OT:

"ControlSend/Send not working accurately" is definitely not true! With this title you insinuate that the AutoIt-developers are lazy dumbasses not fixing a "bug" since years! They are NOT!

"I am not able to understand how ControlSend/Send works accurately" should be the title! 

 

BTT:

After activating a Window it is highly recommended to wait until the activation of this Window! In your example the Send("{TAB}") is executed immediately after the WinActivate($hWND)! At this time, Windows is processing the activation of the window, and nobody knows if the window is active or not. You have to ensure that the Window is active, maybe "WinWaitActive" would good to start with....

I don't know if autoit developers are lazy and I can't understand why you are claiming that. To be honest; I can barely understand what you are saying.

As for what you are claiming about autoit:
Everybody can know "if the window is active or not" by using WinActive().

 

P.S. this is not facebook. If you need some attention go there or take a pet.

Share this post


Link to post
Share on other sites

ControlSetText = 99.99999% accurate...even without an active window.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

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  
Followers 0

  • Similar Content

    • Jefrey
      By Jefrey
      I've made this HTTP lib to simplify HTTP requests, mainly when dealing about POST data or file uploads.
      Three functions are available:
      string _HTTP_Get ( string $sURL ) string _HTTP_Post ( string $sURL , string $sPostData ) string _HTTP_Upload ( string $sURL , string $sFilePath , string $sFileField , string $sPostData = '' , string $sFilename = Default) Additionaly, two helper functions are also available:
      URLEncode($sStr) URLDecode($sStr) Full documentation: https://github.com/jesobreira/HTTP.au3/blob/master/README.md
      Fork me on Github: https://github.com/jesobreira/HTTP.au3
      Download lib + docs: https://github.com/jesobreira/HTTP.au3/archive/master.zip
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning
      I would like to know if I can use the Excel UDF to manipulating a .csv file without having Office installed on the PC I'm going to work...
      I read somewhere that it could be done, but I'm here to ask and be sure of what I remember... 
      I'd like to post another question...
      How can I retrieve the handle of a windows from a PID of an .exe?
      I have my script that does a ShellExecute ( which returns the PID of the .exe ), and then, switching a parameter read from a .ini file, adapt the Window on the screen ( Maximize, Minimize, On Top )...
      I tried, but without having success with this:
       
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile_x64=prova.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> #include <WinAPIEx.au3> #include <Array.au3> Local $sFileConfigurazione = @ScriptDir & "\configurazione_exe.ini" If(FileExists($sFileConfigurazione)) Then Local $aSezioniIni = IniReadSection($sFileConfigurazione, "CONFIGURAZIONE_EXE") If @error Then MsgBox($MB_ICONERROR, "Errore!", "Errore durante l'apertura del file: " & @CRLF & $sFileConfigurazione & @CRLF & "Errore: " & @error) Else ; Lancio dell'applicativo indicato nel file di configurazione Local $iPID = ShellExecute($aSezioniIni[1][1]) Local $hWnd If($iPID <> 0) Then Local $aWinList = WinList() For $i = 1 To $aWinList[0][0] If(WinGetProcess($aWinList[$i][1] = $iPID)) Then $hWnd = $aWinList[$i][1] EndIf Next Switch($aSezioniIni[2][1]) Case $aSezioniIni[2][1] = "MIN" WinSetState($hWnd, "", @SW_MINIMIZE) Case $aSezioniIni[2][1] = "MAX" WinSetState($hWnd, "", @SW_MAXIMIZE) Case $aSezioniIni[2][1] = "TOP" WinSetOnTop($hWnd, "", $WINDOWS_ONTOP) EndSwitch EndIf EndIf EndIf It just set on top the .exe I'm launching...
      Thanks
    • rcmaehl
      By rcmaehl
      A UDF with Extended Functions for Window Management

      DISCLAIMER:
      This UDF is still in the development phase. All code works and should be generally bug free, however function names and parameters are subject to change.
       
      Notes:
      Fixes _WindowGetClassList's barbaric returning of a @LF separated string instead of an array.
       
      Potential Uses:
      Automating applications that change their controls' handles/classes on each launch (e.g. half of Cisco's programs)
       
      Functions:
      _WinGetClassList
      _WinGetClassNNList
      _WindowGetHandleList
      _WindowGetHandleListFromPos
       
      Download: 
      WindowEx.zip  (v0.4)
       
      Changelog:
      10/04/2016 (v0.4): _WinGetClassNNList Fixed : Not Returning an Index when using $2D_ARRAY _WinGetClassNNList Fixed : Not Properly returning $aArray[x][1] on Classes with instances > 9 when using $2D_ARRAY 10/03/2016 (v0.3): _WinGetClassList Added : Exactly the same as WinGetClassList but returns a more civilized Array _WinGetClassNNList Added : Returns Classes and their instances in either a 1D or 2D array depending on Flags _WindowGetHandleList Renamed: _WinGetHandleList SCRIPT BREAKING! _WindowGetHandleListFromPos Renamed: _WinGetHandleListFromPos SCRIPT BREAKING! 10/01/2016 (v0.2): WindowsExConstants.au3 Added : Flags in _WindowGetHandleListFromPos _WindowGetHandleListFromPos Removed: ConsoleWrite left in during debug _WindowGetHandleListFromPos Added : Flag for if part of a Control is at $X, $Y return it as well. 10/01/2016 (v0.1): _WindowGetHandleList Added : Retrieves the handles of classes from a window. _WindowGetHandleListFromPos Added : Retrieves the handles of classes at a specific position from a window. Known and Reported Bugs:
      None reported To Do:
      To Be Decided. Opinions welcome! Upcoming Changes:
      To Be Decided.
    • caramen
      By caramen
      Hello guys.
      I have got this script
      $iPid = run("Powershell Get-ADUser "&$UserNameReaded&" -Properties * | select -Expand EmailAddress" , @WindowsDir , @SW_HIDE , 0x2) $MailUser = "" While 1 $MailUser &= StdoutRead($iPID) If @error Then ExitLoop EndIf WEnd GUICtrlSetData ($Label015, ""&$MailUser) If $MailUser = "" Then GUICtrlSetData ($Label017 , "N/A"&$MailUser) Everything is working fine i got correct value
      For my account the value is for exemple :
      J.Personnal@Enterprise.com in the $Label017 the value is correct i have still
      J.Personnal@Enterprise.com If i use :
      Send (""&$MailUser) i have now :
      J.Personnalnterprise.com Is there a way to correct this ?
    • SkysLastChance
      By SkysLastChance
      Okay so I am not sure if I can do this or not with the code I currently have but, I would like to send lastname and the first name with a comma inbetween. 
      so it would look like "last name,first name" 
      right now I just have it sending the last name.
      any help or sugestions are appreciated. 
       
      $r = 1 Local $aArray = _Excel_RangeRead($oExcel, Default, Default) For $i = 1 To UBound($aArray) - 1 ;$i =0 Start from row A $sR1 = $aArray[$i][0] ;status $sR2 = $aArray[$i][1] ;first name $sR3 = $aArray[$i][2] ;Last name $sR5 = $aArray[$i][5] ;Email Address WinWaitActive ("[CLASS:MGUIWin]") Sleep (100) ControlSend("[CLASS:MGUIWin]", "", "Edit2", $sR3, & @CR) $r = $r + 1 If $r > $sBox Then Exit Endif Next