Jump to content

ControlSend script blocking bug?


milos83
 Share

Recommended Posts

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 by milos83
Link to comment
Share on other sites

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

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

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

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 Gude
How 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

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.

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

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 Gude
How 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

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 by benners
Link to comment
Share on other sites

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

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 Gude
How 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

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

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 by milos83
Link to comment
Share on other sites

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 by Earthshine

My resources are limited. You must ask the right questions

 

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