Sign in to follow this  
Followers 0
MaxG

ControlSend Anomaly & Other Questions

13 posts in this topic

Hello All,

I saw an anomaly in ControlSend that I can't reproduce but I was curious if anybody has seen something similar.

Here is some code:

Const $dirFinishedJobs = "C:\Users\MaxG\Desktop\Script Test Files\TEST_ENVIRONMENT\Finished_Jobs"
Local $JobNum = "3717"
Local $ControlText = ""

$ControlText = ControlGetText("Save", "Label Layout Report.pdf", "[CLASS:Edit; INSTANCE:1]")
ControlSend("Save", "Label Layout Report.pdf", "[CLASS:Edit; INSTANCE:1]", $dirFinishedJobs & "\" & $JobNum & "\" & $ControlText & "{ENTER}")

99% of the time the text sent via ControlSend results in:

C:UsersMaxGDesktopScript Test FilesTEST_ENVIRONMENTFinished_Jobs3717Label Layout Report.pdf

...but on rare occasions the text sent via ControlSend results in:

C:|UsersMaxGDesktopScript Test FilesTEST_ENVIRONMENTFinished_Jobs3717Label Layout Report.pdf

I'm wondering what could cause the first slash to occasionaly become a pipe.

Now for "Other Questions"

The following block of code was being skipped over when executing straight out of SciTE using F5:

;Const and vars copied from program header, the block of code in question is the FileExists validation block.
;------------------------------------------------------------------------------------------------------------
Const $dirFinishedJobs = "C:\Users\MaxG\Desktop\Script Test Files\TEST_ENVIRONMENT\Finished_Jobs"
Local $JobNum = "3717"
Local $microDelay = 250

If FileExists($dirFinishedJobs & "\" & $JobNum) Then
    Sleep($microDelay)
    FileDelete($dirFinishedJobs & "\" & $JobNum)
Else
    Sleep($microDelay)
    DirCreate($dirFinishedJobs & "\" & $JobNum)
EndIf

....but when I loaded Towner's AutoIt graphical debugger (version 0.47.0.0 ) and ran it (in production mode) without modifying the code it worked fine.  AND when I closed the debugger and re-ran with F5 in SciTE without modifying the code, it acted like there had never been a problem in the first place without any intervention on my part.

Why could that be?

Lastly

  1. How many of you notice small anomaly such as these when running scripts straight out of SciTE with F5?   (Is it just me?)
  2. How do you adjust/validate for seemingly random results from unchanged code?
  3. Do you find that anomalous situations are reduced by compiling to .exe?

Version info:

AutoIt v3.3.10.2

AutoIt3Wrapper v.2.1.4.4

SciTE v.3.3.7.0

 

As always, any and all insight/suggestions are appreciated.

Thanks in advance,

MaxG

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Use ControlSetText.  The less sends, the better.  I have never come across this issue, but I never use (or as infrequently as possible) use ControlSend|Send.

Somewhere on your station, while sending, something must have sent the shift key, which caused the to be sent as |.  Maybe as the result of a stuck key, or any number of things.

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.

Share this post


Link to post
Share on other sites

jdelaney,

Thank you for your input.  I've never used ControlSetText, but I'm also fairly new to AutoIt.  I will definitely try it out.  My current workaround attempt was to increase the delay between sent keystrokes, but it sounds like your suggestion will set the text as an entire string rather than as a stream of characters - sounds good to me.

 

All,

If anybody else has suggestions or comments regarding this post, please feel free to add to the conversation.  ^_^

Share this post


Link to post
Share on other sites

If you want to stick with the controlsend, then at the end of controlsend, you should validate that the text is as you expect it (controlgettext), else re-enter it after clearing.


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

That is an excellent idea!  Right now my script is sort of a rough draft that does not contain a lot of the validation that I intend to implement in the production version.

I've replaced a few ControlSend statements with ControlSetText statements and the results are positive. I do really like the concept of applying a string rather than a stream of individual characters.  It's a little faster and I feel like it ought to be a bit more stable.

I'm using a lot of Send/ControlSend statements at this time.  I'm going to replace the ControlSend statements in most cases.  The Send statements are controlling some non-standard list view controls (ie:  {DOWN}{DOWN}{ENTER} to select static items or sending text to jump to variable list items) and in some cases to invoke keyboard shortcuts.

I'm debating on going back and navigating the menu system with MouseClicks since WinMenuSelectItem does not appear to function on the menus I'm working with.

If you have anything more to add, I'm all ears.  :D

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Put the autoit window info tool over you menu.  It might actually be a toolbar, which you may, or may not, be able to get the commandid's from to manipulate the 'buttons'

_GUICtrlToolbar_*

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.

Share this post


Link to post
Share on other sites

I just tired but no luck...  I'm using some mailing software, SysExporter, and Acrobat XI.  None of these application's menus highlight when I put the info tool target on them.  I dropped it on them anyway, and checked the info tool's "Toolbar" tab, but nothing present there either.

Worth a try though.   ^.^

Share this post


Link to post
Share on other sites

Sounds like a menu then...try the _guictrlmenu_* functions.

Note: that if you open the 'file' menu, a new menu is created, and you need to work with that new menu (there are functions to grab that).


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

Thanks for the tip!

I'm looking into the _guictrlmenu_* functions, but my initial tests didn't work so well...

I did play with WinMenuSelectItem , the results are as follows:

WinMenuSelectItem works with Notepad
WinMenuSelectItem works with SysExporter

WinMenuSelectItem does not work with Mail Software
WinMenuSelectItem does not work with Acrobat

Still not sure how to "click" items with _guictrlmenu_* functions but, I confess, I'm still working through some examples.  Most examples I looked at involve menus created with _GUICtrlMenu_CreateMenu() but I know from using GuiTab.au3 that creating the control in code is not necessarily a requirement - it works on existing applications.

I'll keep trying out the functions you suggested and see where I get.

Share this post


Link to post
Share on other sites

Maybe I'm giving up too quickly, but I think for now I'll stick with using Send in conjunction with keyboard shortcut commands to access menu items....

I can't get _GUICtrlMenu functions to "click" menu items for the life of me and, considering that WinMenuSelectItem did not produce results in two of the applications I'm controlling I'm afraid this is a dead end.

I do, however, appreciate the suggestion.

If you or anyone else have other thoughts on the subjects discussed in the original topic, or on the topic of Send alternatives, please feel free to comment.

Share this post


Link to post
Share on other sites

Try this on your window:

#include <GuiMenu.au3>
$hWin = WinGetHandle("yourwindow")
$hMenu = _GUICtrlMenu_GetMenu($hWin)
$iCount = _GUICtrlMenu_GetItemCount($hMenu)
For $i = 0 To $iCount-1
    ConsoleWrite(_GUICtrlMenu_GetItemText($hMenu,$i) &  @CRLF)
Next

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

#12 ·  Posted (edited)

Ok, I tried your code and only the @CRLF's registered in console.

As an alternate test I converted the ConsoleWrite statement to a MsgBox statement (without @CRLF) and got a series of blank message boxes.

For testing sake, I also ran this against Adobe Acrobat, but the results are the same.

I would have to conclude that, at the very least, a method that works against Adobe Acrobat would also succeed against my Mail Software.

Edited by MaxG

Share this post


Link to post
Share on other sites

I should also add:  Thank you for your efforts, I appreciate it!

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