milos83 Posted January 17, 2018 Share Posted January 17, 2018 (edited) In this reproducer the ControlSend will block the script from finishing. I do know that control with the ID of 0 probably doesn't exists, but nevertheless, this is unexpected behaviour. Tested in Win 10 Autoit: v3.3.14.2 $gGUIDummy = GUICreate("") Run("notepad.exe") $HWND = WinWait("Untitled - Notepad") WinActivate($gGUIDummy) ControlSend($HWND, "", 0, "!f") ;control Id 0 is the issue here Edited January 17, 2018 by milos83 Link to comment Share on other sites More sharing options...
jdelaney Posted January 17, 2018 Share Posted January 17, 2018 Use this instead: WinMenuSelectItem Sends generally don't work if the window is not active. 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. Link to comment Share on other sites More sharing options...
milos83 Posted January 17, 2018 Author Share Posted January 17, 2018 8 hours ago, jdelaney said: Use this instead: WinMenuSelectItem Sends generally don't work if the window is not active. Thanks, but I don't need a workaround. I'm just checking to see if this is a bug since ControlSend should never block execution. Link to comment Share on other sites More sharing options...
alienclone Posted January 17, 2018 Share Posted January 17, 2018 ControlSend is not blocking execution, your dummy gui is causing a problem, when i removed it from the script everything completed. If @error Then MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!") EndIf "Yeah yeah yeah patience, how long will that take?" -Ed Gruberman REAL search results | SciTE4AutoIt3 Editor Full Version Link to comment Share on other sites More sharing options...
milos83 Posted January 17, 2018 Author Share Posted January 17, 2018 Just now, alienclone said: ControlSend is not blocking execution, your dummy gui is causing a problem, when i removed it from the script everything completed. Are you serious? Link to comment Share on other sites More sharing options...
alienclone Posted January 17, 2018 Share Posted January 17, 2018 2 minutes ago, milos83 said: Are you serious? usually If @error Then MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!") EndIf "Yeah yeah yeah patience, how long will that take?" -Ed Gruberman REAL search results | SciTE4AutoIt3 Editor Full Version Link to comment Share on other sites More sharing options...
milos83 Posted January 17, 2018 Author Share Posted January 17, 2018 Just now, alienclone said: usually That code is showing how in certain condition the ControlSend is blocking further script execution. You can't remove a part of code and say "Here! It doesn't block anymore!" XD Link to comment Share on other sites More sharing options...
alienclone Posted January 17, 2018 Share Posted January 17, 2018 add to see which line of code is hanging. Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info If @error Then MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!") EndIf "Yeah yeah yeah patience, how long will that take?" -Ed Gruberman REAL search results | SciTE4AutoIt3 Editor Full Version Link to comment Share on other sites More sharing options...
milos83 Posted January 17, 2018 Author Share Posted January 17, 2018 4 minutes ago, alienclone said: add to see which line of code is hanging. Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info Can't be used because as soon as you give focus to anything else, the ControlSend finishes. Simple ConsoleWrite is enough. Here, run this, don't click anything and see for yourself $gGUIDummy = GUICreate("") Run("notepad.exe") $HWND = WinWait("Untitled - Notepad") WinActivate($gGUIDummy) ConsoleWrite("Sending..." & @CRLF) ControlSend($HWND, "", 0, "!f") ;control Id 0 is the issue here Link to comment Share on other sites More sharing options...
BrewManNH Posted January 17, 2018 Share Posted January 17, 2018 It is working for me, if you change the WinActivate line to the Notepad window instead of your invisible window. As previously stated, sometimes windows resist automation unless they're the active window. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
alienclone Posted January 17, 2018 Share Posted January 17, 2018 1 minute ago, milos83 said: Can't be used because as soon as you give focus to anything else, the ControlSend finishes. Simple ConsoleWrite is enough. Here, run this, don't click anything and see for yourself $gGUIDummy = GUICreate("") Run("notepad.exe") $HWND = WinWait("Untitled - Notepad") WinActivate($gGUIDummy) ConsoleWrite("Sending..." & @CRLF) ControlSend($HWND, "", 0, "!f") ;control Id 0 is the issue here this reproduced the error for me and you are correct, it is hanging at controlsend. did not realize that my act of changing focus was the reason the script was finishing for me. milos83 1 If @error Then MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!") EndIf "Yeah yeah yeah patience, how long will that take?" -Ed Gruberman REAL search results | SciTE4AutoIt3 Editor Full Version Link to comment Share on other sites More sharing options...
BrewManNH Posted January 17, 2018 Share Posted January 17, 2018 I tried this numerous times, it never hung for me. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
benners Posted January 17, 2018 Share Posted January 17, 2018 (edited) If it is the controlId that is the issue, try specifying the control $gGUIDummy = GUICreate("") Run("notepad.exe") $HWND = WinWait("Untitled - Notepad") WinActivate($gGUIDummy) ConsoleWrite("Sending..." & @CRLF) ControlSend($HWND, "", "[CLASS:Edit; INSTANCE:1]", "!f") ;control Id 0 is the issue here There is also the issue of the characters you're sending. If your trying to drop down the file menu on notepad, it will have to be the active window to access the menu. Edited January 17, 2018 by benners Link to comment Share on other sites More sharing options...
alienclone Posted January 17, 2018 Share Posted January 17, 2018 i think general help and support forum may only bring "do X to workaround". maybe the development forum may have answers to WHY the command is hanging instead of exiting the script immediately and throwing the error code. If @error Then MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!") EndIf "Yeah yeah yeah patience, how long will that take?" -Ed Gruberman REAL search results | SciTE4AutoIt3 Editor Full Version Link to comment Share on other sites More sharing options...
BrewManNH Posted January 17, 2018 Share Posted January 17, 2018 46 minutes ago, alienclone said: may have answers to WHY the command is hanging instead of exiting the script immediately I have never had this script hang ever, it immediately returns after the ControlSend command for me. Probably an issue on the computers being used. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
jdelaney Posted January 18, 2018 Share Posted January 18, 2018 (edited) I'm able to reproduce the hang, along with the window error tone. Like I said though, it's because sends in Microsoft environments are flakey on inactive windows. ControlSetText will work fine, WinMenuSelectItem will work fine, but Send and ControlSend will not. This isn't anything to do with autoit...if you think it's a bug, create one at Microsoft. Workaround 1: $gGUIDummy = GUICreate("") Run("notepad.exe") $HWND = WinWait("Untitled - Notepad") WinActivate($gGUIDummy) ConsoleWrite("Sending..." & @CRLF) ;~ ControlSend($HWND, "", "", "!f") ;control Id 0 is the issue here WinMenuSelectItem($hWnd,"","&File","&Save") ConsoleWrite("sent..." & @CRLF) Workaround 2: $gGUIDummy = GUICreate("") Run("notepad.exe") $HWND = WinWait("Untitled - Notepad") WinActivate($gGUIDummy) ConsoleWrite("Sending..." & @CRLF) ;~ ControlSend($HWND, "", "", "!f") ;control Id 0 is the issue here ;~ WinMenuSelectItem($hWnd,"","&File","&Save") Run(@AutoItExe & ' /AutoIt3ExecuteLine "ControlSend(Hwnd(' & $HWND & '), '''', '''', ''!f'')"') ConsoleWrite("sent..." & @CRLF) Then again, maybe I'm wrong, and this should be checked out by a developer here. Interesting that initiating a new process to do the controlsend does not deadlock. Scenario 1 (provided by original poster), ControlSend to open the file menu on an inactive window causes a windows 'error' tone, and the file menu does not open. Script is deadlocked until user does some action (a mouse click, or a send) Workaround 1: opens save menu as expected, no deadlock Workaround 2: should have same results as Scenario 1, theoretically, but instead, there is no deadlock, no 'error' tone, and the File menu opens. @Jos, can you enlighten us? Edited January 18, 2018 by jdelaney 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. Link to comment Share on other sites More sharing options...
milos83 Posted January 18, 2018 Author Share Posted January 18, 2018 (edited) 10 hours ago, jdelaney said: Interesting that initiating a new process to do the controlsend does not deadlock. That's another reason why I think that it is actually an autoit causing the problem. ControlSend works fine on inactive windows. Problem occurs specifically when my own created gui is in focus and I want to ControlSend another window. Another test shoved that the Windows Error Tone is because ControlSend actually sent, but to the wrong window. ControlSend($HWND, "", 0, "!f") When third parameter is 0, ControlSend will be sent to currently active window. Being that (in the example) the current active window is autoit gui without a menu, it creates the error sound. Edited January 18, 2018 by milos83 Link to comment Share on other sites More sharing options...
milos83 Posted January 22, 2018 Author Share Posted January 22, 2018 bump Link to comment Share on other sites More sharing options...
Earthshine Posted January 22, 2018 Share Posted January 22, 2018 (edited) maybe you should file a bug in their system. I get the results you get btw Edited January 22, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Earthshine Posted January 22, 2018 Share Posted January 22, 2018 (edited) I just tested the workaround 1 that was posted above. I commented out the first line and added a declaration for the dummy. Works!! ;~ $gGUIDummy = GUICreate("") Local $gGUIDummy Run("notepad.exe") $HWND = WinWait("Untitled - Notepad") WinActivate($gGUIDummy) ConsoleWrite("Sending..." & @CRLF) ;~ ControlSend($HWND, "", "", "!f") ;control Id 0 is the issue here WinMenuSelectItem($hWnd,"","&File","&Save") ConsoleWrite("sent..." & @CRLF) I think as long as you use a valid dummy variable (not defined on the fly, EVER) it seems to work. no errors. Edited January 22, 2018 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now