Sign in to follow this  
Followers 0
Batch

Recording My Installs

11 posts in this topic

#1 ·  Posted (edited)

OK, I like my little function that sets the WinState to hidden, then sends a {SPACE} to the function to trigger it, and I want that to be my new standard for creating scripts. My slacker coworkers won't script anything, so I'd like to write something to record an installation. Now there are these cool functions of WinGetTitle, and WinGetText, so I have made this so far:

HotKeySet( "^!g", "recordit" )

While 1
Wend

Func recordit( $title, $text )
$title = WinGetTitle( "", "" )
$text = WinGetText( "", "" )
MsgBox( 0, $title, $text )
EndFunc

Edit: Was on the phone with a user, wasn't paying attention, I realize I didn't complete my post. The part I can figure out how to record is the control I am manipulating. Obviously, I can do a filewriteln with the variables that I have, and create another autoit script for the install, but how do I record the button that I am about to click? Can I somehow put the focus (tab over to the button) and then say record the control that has the focus? This would be really useful for anyone using AutoIt to roll out applications, could save a lot of time. You'd just highlight the button you are going to hit, and do ctrl alt g and it would dump that page to a file, then move on. Anyway, let me know what ya'll think I should do next.

Edited by Batch

Share this post


Link to post
Share on other sites



Might want to add a Sleep(50) in the While loop to minimize CPU usage.

Share this post


Link to post
Share on other sites

Dang dude, that's pretty hot. You ought to toot your horn. However, and don't be let down or anything, I am VERY impressed, hehe, I was something that's a little cleaner and doesn't rely on mouse movements, but I want to manipulate the controls directly, because I am going to have each page run this function:

Func click( $title, $text, $button)
WinWait( $title, $text )
WinSetState( $title, $text, @SW_HIDE )
ControlSend( $title, $text, $button, "{SPACE}" )
EndFunc

That way the window is taken off screen before manipulated, and even if the user is doing something else, they won't be affected by the install. How can I capture the control to a variable, or would I have to write something in c to do that (hehe, which I can't do, cause I'm not cool like all you kids)?

Share this post


Link to post
Share on other sites

OK, slap me and call me Susan, I just found "ControlGetFocus" :whistle: My dearest apologies, man, ya'll will never help me again!

:iamstupid:

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Actually controlgetfocus does return the classnameNN , so you use that to write your script quite easy

Edit, I was using a window that had no controls and typed a bit too fast. :iamstupid:

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Man, this sucks :crytowel: I think I'll just quit and feel sorry for myself, the FileWriteLine statement is too complicated to do

FileWriteLine( $file, "click( " & "" " & $title...

I can't handle the double quote things, and based on what Kitty said, I think I'm fighting a losing battle anyway.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

yea, and you can always assing quotes if you need to, or many other tricks:

$Q1="'"
$Q2='"'
; or 
; remember '=chr(39)
; remember "=chr(34)

It can get a little tricky, but most you will only have to write once.

Use a lot of functions :whistle:

Run("notepad.exe")
WinWaitActive("Un")
$x=ControlGetFocus("Un")
sendline("Hello World")

Func sendline($send)
FileWriteLine( "mynewthing.au3",'Controlsend("' & WinGetTitle ( "" ) &'","'& WinGetText ( "" ) & '","' & $x & '","'&$send&'")')
EndFunc
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Alright ya'll thanks for the encouragement, here's what I have so far:

Opt( "WinTextMatchMode", 2 )

$file = FileOpen( "c:\temp\script.au3", 1 )
$quit = 0
$runwhat = InputBox( "Enter the installation path", "Path to EXE:" )

HotKeySet( "^g", "recordit" )
HotKeySet( "^!q", "quit" )

Run( $runwhat )

FileWriteLine( $file, 'Opt( "WinDetectHiddenText", 1 )' )
FileWriteLine( $file, 'Opt( "TrayIconDebug", 1 )' )
FileWriteLine( $file, "")
FileWriteLine( $file, 'Run( "' & $runwhat & '" )' )
FileWriteLine( $file, "")

While $quit <> 1
Sleep( "50" )
Wend

FileWriteLine( $file, "" )
FileWriteLine( $file, 'Func click( $title, $text, $button)' )
FileWriteLine( $file, 'WinWait( $title, $text )' )
FileWriteLine( $file, 'WinSetState( $title, $text, @SW_HIDE )' )
FileWriteLine( $file, 'ControlSend( $title, $text, $button, "{SPACE}" )' )
FileWriteLine( $file, 'EndFunc' )

Func recordit()
$title = WinGetTitle( "", "" )

$text = WinGetText( "", "" )
$text = StringLeft( $text, 10 )
$text = StringReplace( $text, chr(10), chr(39) & " " & chr(38) & " " & "chr(10) & " & chr(39) )

$button = ControlGetFocus( "", "" )
FileWriteLine( $file, "click( " & chr(39) & $title & chr(39) & ", " & chr(39) & $text & chr(39) & ", " & chr(39) & $button & chr(39) & " )" )
EndFunc

Func quit()
$quit = 1
EndFunc

When I run the old Autoit 2.64 executable, and do Ctrl+G to capture the screen, here's the resulting script.au3:

Opt( "WinDetectHiddenText", 1 )
Opt( "TrayIconDebug", 1 )

Run( "c:\files\autoit.exe" )

click( 'WinZip Self-Extractor', 'OK' & chr(10) & 'AutoIt ', 'Button1' )
click( 'WinZip Self-Extractor - AutoIt.exe', '&Setup' & chr(10) & 'Can', 'Button1' )
click( 'AutoIt v2.64 Setup', '&Modify' & chr(10) & '&R', 'Button4' )

Func click( $title, $text, $button)
WinWait( $title, $text )
WinSetState( $title, $text, @SW_HIDE )
ControlSend( $title, $text, $button, "{SPACE}" )
EndFunc

When I actually run it, it gets hung (Sorry Larry!) on Line 9, and it doesn't recognize the text (i guess 'cause the chr(10) things). What am I doing wrong or how do I get around this? TIA! This is fun. Once Larry explained the quotes, it wasn't that hard, I have read the help file, but I suppose it never clicked?

EDIT: When you use the window spy and it finds all kinds of text, there's plenty of chr(10)'s in there, if I'm overlooking some easy way of avoiding this let me know. Whew! What a challenge! (for me it is...stop laughing!)

Edited by Batch

Share this post


Link to post
Share on other sites

Yeah dude, it's the resulting script, I think it has to do with the chr(10) in there. I didn't have to change the sleep statement, it worked fine for me. It's all in the text variable created in the resulting script, I'm not sure how to code that part.

Share this post


Link to post
Share on other sites

I posted a couple of useless ditties until I figured the problem... WinGetText inserts @LF that does not even exist in the window. So, you will have to truncate at the @LF, cause you will not know if it came from the window or not...

$text = StringLeft( $text, 20 )
If StringInStr( $text, @LF ) Then
     $text = StringLeft( $text, StringInStr( $text, @LF) - 1 )
EndIf

Hmm, maybe that is a bug JP was talking to me about ages ago but I didn't understand.

Share this post


Link to post
Share on other sites

Hmm, maybe that is a bug JP was talking to me about ages ago but I didn't understand.

Definetly I should learn better English.

Anyway perhaps there is a difficulty to differentiate a true ending @LF from a false ? :whistle:

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