Sign in to follow this  
Followers 0
Risso

Trouble with ControlCommand

3 posts in this topic

Since this is my first post - I have learned a great deal from these forums as a guest... thanks

And I have dug into the help files and forums to get this far (I am using Autoit to automate some processes used by me and my coworkers)

and now I have hit a sticking point... I have run into the problem below a number of times, here is a specific example:

This bit of code uses "controlcommand" and "controlsend" on a Macromedia Authorware lesson.

It functions - but only in a "stand alone" environment... as soon as I try to add this to an Autoit created GUI it stops working.

I am guessing that once I crank up another window my code is missing something to identify the window. Authorware doesn't play nice with

Autoit and I have spotty success extracting window handles/control IDs.

Specifically, this breaks when I do the function (Func ClickDone ($ID)) located at the bottom of this code box. Run as you see it here (No GUI) the function

turns off any active "Done" buttons - as you can see from the "while command" then activates either the "Functions" or "Variables" panel depending on which I am working with. Inside a GUI it will turn off the "Done" buttons, but then the Controlsend after that doesn't work.

I realize this you cannot run this utility -- but I am hoping someone out there far better at these commands will see what I am missing.

Thanks!

CODE
Local $string = "SEC_WEP_MIL" ; Test file

local $list = CleanFuncandVar ($string) ; Function call as it would appear when used...

msgbox (4096,"List", $list)

;===============================================================================

; Function Name: CleanFuncandVar ($string)

; Description: Returns tabbed list of operations performed.

; Parameter(s): $string - The Authorware Lesson title currently being worked with.

; Requirement(s): File specified in $string must be open in Authorware window

; Return Value(s): On Success - tabbed list of operations performed (lesson filename, unused variables removed, unused functions removed.

; On Failure - Empty string

; Author(s): Risso

; Note(s): According to authorware forums - max variable/function count will not exceed 2978 user variables/functions (ea)...

;

;===============================================================================

Func CleanFuncandVar ($string)

Local $list = '' ; initialize return string

Local $last, $current, $temp, $x, $y, $z, $i

Local $begin = TimerInit() ; elapsed time counter begin ...

ControlFocus ( "Authorware","","") ; unecessary in stand alone test, but used in GUI testing

For $x = 0 to 1 ; 0 is var -- 1 is func

ClickDone ($x) ; Close all windows and open variables and functions one at a time.

For $y = 0 to 1 ; 0 is a7p -- 1 is a7l

$i = 0 ; counter variable (used to accumulate number of var/func deleted.

$list = $list & AssignFile ($y, $string) & @TAB ; add to Returned string

Select

Case $x = 0 ; variables

$list = $list & 'Variables:' & @TAB ; add to Returned string

For $z = 0 to 4000 ; maximum variable/function count is 2978, but system variables are 350+

ControlCommand ( "Authorware", "", "[iD: 4]", "SetCurrentSelection", $z ) ; highlight item in drop down...

$current = ControlCommand("Authorware","","[iD:4]", "GetCurrentSelection", "") ; capture item selected

If $last = $current then ExitLoop ; all items are unique -- if we see the same name it means we are at the last item -- so exit

; If delete button is enabled - then "click" on it -- the next item on the list will automatically get the focus, and if it is also

; unused - "delete" will remain active. However, when the item is in use "Delete" will be inactive and we need to advance to the Next

; drop down item and test again (incrementing $x)

If ControlCommand ( "Authorware", "", "[CLASS:Button; TEXT:Delete]","IsEnabled", "") Then

while ControlCommand ( "Authorware", "", "[CLASS:Button; TEXT:Delete]","IsEnabled", "")

$i = $i + 1 ; accumulate a count of items deleted

ControlClick("Authorware", "", "[CLASS:Button; TEXT:Delete]", Default ,1)

WEnd

EndIf

$last = ControlCommand("Authorware","","[iD:4]", "GetCurrentSelection", "") ; capture item for comparison to $current for exitloop

Next

$list = $list & $i & @TAB ; add to Returned string

Case $x = 1 ; Functions

$list = $list & 'Functions:' & @TAB ; add to Returned string

For $z = 0 to 3000 ; Simpler loop - functions however are not uniquely named, so all "3000" are done.

ControlCommand ( "Authorware", "", "[iD: 4]", "SetCurrentSelection", $z )

If ControlCommand ( "Authorware", "", "[CLASS:Button; TEXT:Unload]","IsEnabled", "") Then ; see loop above diff. is "unload" vs. "delete"

while ControlCommand ( "Authorware", "", "[CLASS:Button; TEXT:Unload]" ,"IsEnabled", "")

$i = $i + 1 ; accumulate a count of items deleted

ControlClick("Authorware", "", "[CLASS:Button; TEXT:Unload]", Default ,1) ;

WEnd

EndIf

Next

$list = $list & $i & @TAB ; add to Returned string

EndSelect

Next

$list = $list & @LF ; add to Returned string line feed at end of var/func output

Next

ClickDone (2) ; sent with "2" is invalid ID - only closes windows.

$dif = TimerDiff($begin) ; capture elapsed time -- operations are split for documentation, could be combined...

$dif = Round($dif/1000, 1) ; divide by 1000 to get seconds -- ,1 for 1 decimal place (10ths of second)

$list = $list & "Elapsed Time: " & $dif & @LF ; elapsed time in seconds typical time is 15 - 20 seconds...

Return $list ; Return the list for use elsewhere.

EndFunc ; <<== CleanFuncandVar

;===============================================================================

; Function Name: AssignFile ($ID, $string)

; Description: Returns extensions on $string. (.a7p / .a7l) based on ID 0 or 1

; Parameter(s): $ID = 0 returns a7p (program)

; $ID = 1 returns a7l (library)

; $string - The Authorware Lesson title currently being worked with.

; Requirement(s): File specified in $string must be open in Authorware window

; Return Value(s): On Success - The input $string with extension (.a7p / .a7l)

; On Failure - empty string

; Author(s): Risso

; Note(s):

;

;===============================================================================

Func AssignFile ($ID, $string)

Local $a7pstring = $string & '.a7p'

Local $a7lstring = $string & '.a7l'

Select

Case $ID=0

$i = ControlCommand("Authorware","","[iD:3]", 'FindString', $a7pstring)

ControlCommand ( "Authorware", "", "[iD:3]", "SetCurrentSelection", $i )

Return $a7pstring

Case $ID=1

$i = ControlCommand("Authorware","","[iD:3]", 'FindString', $a7lstring)

ControlCommand ( "Authorware", "", "[iD:3]", "SetCurrentSelection", $i )

Return $a7lstring

EndSelect

EndFunc ; <<== AssignFile

;===============================================================================

; Function Name: ClickDone ($ID)

; Description: Closes any windows the user may have left open, and opens either

; variables or function window based on $ID

; Parameter(s): $ID = 0 open variable window

; $ID = 1 open function window

; $string - The Authorware Lesson title currently being worked with.

; Requirement(s): Authorware window open with lesson file

; Return Value(s): No returns

; Author(s): Risso

; Note(s):

;

;===============================================================================

Func ClickDone ($ID)

While ControlCommand ( "Authorware", "", "[CLASS:Button; TEXT:Done]","IsEnabled", "")

ControlClick("Authorware", "", "[CLASS:Button; TEXT:Done]", Default ,1)

WEnd

Select

Case $ID = 0

ControlSend ( "Authorware", "", "", "^+v", 0) ; << This doesn't work inside a GUI...

Case $ID = 1

ControlSend ( "Authorware", "", "", "^+f", 0) ; << Neither does this...

EndSelect

EndFunc ; <<== ClickDone

Share this post


Link to post
Share on other sites



ControlSend ( "Authorware", "", "", "^+v", 0) ; << This doesn't work inside a GUI...

ControlSend ( "Authorware", "", "", "^+f", 0) ; << Neither does this...

Shouldn't there be a control ID of some sort in the third parameter?

Despite that, I'm having problems with ControlSend as well, so I will watch this thread.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Shouldn't there be a control ID of some sort in the third parameter?

Despite that, I'm having problems with ControlSend as well, so I will watch this thread.

Thanks for the reply.

Yes, it is certainly better to use a control ID of some sort with a Controlsend. I used the AUTOIT Window Info tool to get the ID numbers that I've included in the script. However, neither that tool nor any of the other functions gave me a usable control ID -- so I was forced to leave it blank.

When I add what I "think" is the control ID...[obtained with any number of functions] it doesn't work... so I posted here hoping to cut out a few hours of troubleshooting.

Since the code worked WITHOUT an AUTOIT GUI - I had to ask myself what could have changed? More importantly, how could I change it back?

The answer is the GUI has "stolen" the focus - so I needed to force the focus back to the window I want -- Like so:

CODE
ControlFocus("Authorware", "", "")

ControlSend ( "Authorware", "", "", "^+v", 0)

This works inside an Autoit GUI - so in my loop from Idiot to knowledge I can put

$Knowledge = $Knowledge + 1 for the day.

Edited by Risso

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