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

    • initspawn
      By initspawn
      Hello,
      I've been trying to automate a process to check in the GUI of a Java program for a certain condition. When I use the Autoit Window information tool I don't get anything under the control tab, which seems to be normal for a Java program. I've been able to automate what I need using ControlSend and checking for the condition using ImageSearch but the Java program will not accept ControlSend unless it is the active window. I'd like to run the script while the window is inactive so I can still use the PC but haven't been able to come up with a solution other than a virtual machine. I even tried sysinternals desktops to create a second virtual desktop but that just causes WinActivate to return a failure after you switch to another virtual desktop. Does anyone have any ideas for getting a window to think its active when its not or an alternative to ControlSend that may work?
      Thanks. 
    • jparnell8839
      By jparnell8839
      I'm hoping this is feasible... I made a program that resides in the system tray. One of the tray items runs a function that waits for the user to click on a window to get the window title.
      I would like for the mouse cursor to change to the cross while waiting for user input. I have tried using GUISetCursor(3), but from my understanding this only changes the cursor for an AutoIt GUI window.
      How could I go about changing the mouse cursor for the user's environment, not just for the AutoIt window?
    • Wingens
      By Wingens
      I am trying to send a CTRL+G to a command prompt.
      It should send something like ^G this to the prompt but instead it sends only the G.
      To give more insight into what I am trying to create here:
      At my work we need a programm to open de cashdrawer using the commandprompt, i created a gui where you can set the COM-port to wich the command should be send.
      This works the COM-port setting is writting in a .ini file to be used every time the program opens.
      I have attached the files to the post.
      Hope someone can help me.
       
       
       
      open.zip
    • manit
      By manit
      hi ,
      I have written a script to simulate keypresses and click on some windows 
      The work is repetitive.
      Here I activate 'foobar' and click on a place in it then press few down arrow keys . Then some keypresses in 'reboot' window ...
      (1)It sometimes happen that am external window pops up taking focus away from action being performed by script . As a result ,say, 'reboot' window does not appear . How should I bring scipt to run from beginning (of while loop) again ?
      (2)I used window info tool to find coordinates of place to click . Is it possible that window info tool keeps updating mouse coordinate even when I do not drag its finder ?
      (3)I would also like to add functionality to do an action on window 'new IP' , if found , in the infinite while loop .
      Please give directions.
      Thanks.

      #include <AutoItConstants.au3> HotKeySet("{ESC}", "dummy") AutoItSetOption("WinTitleMatchMode",2); Local $hWnd, $x, $y, $pos, $reponse While 1 $hWnd = WinGetHandle("foobar") $pos = WinGetPos($hWnd) $x = 360 ;  $y = 77  ;  WinActivate($hWnd) MouseClick("left", $pos[0] + $x, $pos[1] + $y) Send("{DOWN}") WinWaitActive($hWnd) Send("{DOWN}") WinWaitActive($hWnd) Send("{DOWN}") WinWaitActive($hWnd) Send("{DOWN}") WinWaitActive($hWnd) Send("{DOWN}") Send("{DOWN}") WinWaitActive($hWnd) WinWaitActive($hWnd) Send("{ENTER}") $reboot_window = WinWait("Reboot") WinWaitActive($reboot_window) Send("{TAB}") WinWaitActive($reboot_window) Send("{SPACE}") WinWaitActive($reboot_window) Send("{TAB}") WinWaitActive($reboot_window) Send("{DOWN}") Send("{DOWN}") WinWaitActive($reboot_window) Send("{TAB}") WinWaitActive($reboot_window) Send("{DOWN}") WinWaitActive($reboot_window) Send("{TAB}") WinWaitActive($reboot_window) Send("{SPACE}") Sleep(1000) $response = WinGetHandle("Reboot") $pos = WinGetPos($response) $x = 168 ; 530-362 $y = 258  ; 376-118 WinActivate($response) MouseClick("left", $pos[0] + $x, $pos[1] + $y) Sleep(50000) WEnd Func dummy() EndFunc   ;==>dummy
    • rcmaehl
      By rcmaehl
      A UDF with Extended Functions for Window Management

      DISCLAIMER:
      This UDF is still in Alpha 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.