st4vr0s Posted June 11, 2009 Share Posted June 11, 2009 (edited) Hello all, I've searched the forum and tried various code. I can honestly say i've done my best but I'm certainly know coder. Please can anyone help here. Im trying a script that asks me to input a key code the first time its run. After that it never asks again. Below are some examples of my attempts. I'm a little unsure on the best way to achieve my goal. The script below works ok if a Key code hasn't been input at all. CODERun ("C:\Program Files (x86)\Futuremark\3DMark06\3DMark06.exe" ,"C:\Program Files (x86)\Futuremark\3DMark06") If Not WinExists ("Please Register") Then WinWait ("Please Register") WinActivate ("Please Register") WinActivate ("Please Register") WinActivate ("Please Register") WinWaitActive ("Please Register") Sleep(8000) Send ("{tab}") Send ("{tab}") Send ("{tab}") Send ("xxxx-xxxx-xxxx-xxxx-xxxx-xxxx") Send ("{tab}") Send ("{tab}") Send ("{tab}") Send ("{ENTER}") WinWait ("3DMark06" , "Thank you for registering") WinActivate ("3DMark06" , "Thank you for registering") WinActivate ("3DMark06" , "Thank you for registering") WinActivate ("3DMark06" , "Thank you for registering") WinWaitActive ("3DMark06" , "Thank you for registering") Send ("{ENTER}") EndIf WinWait ("Tip Of The Day") WinActivate ("Tip Of The Day") WinActivate ("Tip Of The Day") WinActivate ("Tip Of The Day") WinWaitActive ("Tip Of The Day") Send ("{tab}") Send ("{ENTER}") The script below works ok if I have already input the key code. CODERun ("C:\Program Files (x86)\Futuremark\3DMark06\3DMark06.exe" ,"C:\Program Files (x86)\Futuremark\3DMark06") if WinExists ("Tip Of The Day") Then WinWait ("Please Register") WinActivate ("Please Register") WinActivate ("Please Register") WinActivate ("Please Register") WinWaitActive ("Please Register") Sleep(8000) Send ("{tab}") Send ("{tab}") Send ("{tab}") Send ("xxxxx-xxxx-xxxx-xxxx-xxxx-xxxx") Send ("{tab}") Send ("{tab}") Send ("{tab}") Send ("{ENTER}") WinWait ("3DMark06" , "Thank you for registering") WinActivate ("3DMark06" , "Thank you for registering") WinActivate ("3DMark06" , "Thank you for registering") WinActivate ("3DMark06" , "Thank you for registering") WinWaitActive ("3DMark06" , "Thank you for registering") Send ("{ENTER}") EndIf WinWait ("Tip Of The Day") WinActivate ("Tip Of The Day") WinActivate ("Tip Of The Day") WinActivate ("Tip Of The Day") WinWaitActive ("Tip Of The Day") Send ("{tab}") Send ("{ENTER}") Neither code works the other way round. When my test script runs for a second instance I want to to jump straight to the WinWait ("Tip Of The Day") WinActivate ("Tip Of The Day") WinActivate ("Tip Of The Day") WinActivate ("Tip Of The Day") WinWaitActive ("Tip Of The Day") Send ("{tab}") Send ("{ENTER}") because I know the If Not WinExists ("Please Register") Then WinWait ("Please Register") WinActivate ("Please Register") WinActivate ("Please Register") WinActivate ("Please Register") WinWaitActive ("Please Register") Sleep(8000) Send ("{tab}") Send ("{tab}") Send ("{tab}") Send ("xxxx-xxxx-xxxx-xxxx-xxxx-xxxx") Send ("{tab}") Send ("{tab}") Send ("{tab}") Send ("{ENTER}") WinWait ("3DMark06" , "Thank you for registering") WinActivate ("3DMark06" , "Thank you for registering") WinActivate ("3DMark06" , "Thank you for registering") WinActivate ("3DMark06" , "Thank you for registering") WinWaitActive ("3DMark06" , "Thank you for registering") Send ("{ENTER}") EndIf Will be missed. How do I create a code that does basically if WinExists ("Please Register") then carry on with script WinWait ("Please Register")......... If Window ("Please Register") doesnt exsist then go to WinWait ("Tip Of The Day") WinActivate ("Tip Of The Day") WinActivate ("Tip Of The Day") WinActivate ("Tip Of The Day") WinWaitActive ("Tip Of The Day") Send ("{tab}") Send ("{ENTER}") Sorry if I sound like a n00b Any help would be much appreciated. Thanks Edited June 11, 2009 by st4vr0s Link to comment Share on other sites More sharing options...
Skruge Posted June 11, 2009 Share Posted June 11, 2009 If...Else...EndIf [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
herewasplato Posted June 12, 2009 Share Posted June 12, 2009 Here is one solution that changes very little of your original code so that you can see/follow the modifications.Read thru the comments in the code and post any questions that you might have about them.expandcollapse popupRun("C:\Program Files (x86)\Futuremark\3DMark06\3DMark06.exe", "C:\Program Files (x86)\Futuremark\3DMark06") While 1 ; if a window named "Please Register" exists then ; go do the lines in the User Defined Function (UDF) ; named _Register If WinExists("Please Register") Then _Register() ; once all of the lines of that UDF have completed ; return right back to this loop and wait for a ; window named "Tip Of The Day" ; once a window named "Tip Of The Day" exists ; exit this loop and run the lines after WEnd If WinExists("Tip Of The Day") Then ExitLoop Sleep(100) WEnd WinWait("Tip Of The Day") WinActivate("Tip Of The Day") WinActivate("Tip Of The Day") WinActivate("Tip Of The Day") WinWaitActive("Tip Of The Day") Send("{tab}") Send("{ENTER}") ; the script exits here and does not run the UDF again Func _Register() WinWait("Please Register") WinActivate("Please Register") WinActivate("Please Register") WinActivate("Please Register") WinWaitActive("Please Register") Sleep(8000) Send("{tab}") Send("{tab}") Send("{tab}") Send("xxxx-xxxx-xxxx-xxxx-xxxx-xxxx") Send("{tab}") Send("{tab}") Send("{tab}") Send("{ENTER}") WinWait("3DMark06", "Thank you for registering") WinActivate("3DMark06", "Thank you for registering") WinActivate("3DMark06", "Thank you for registering") WinActivate("3DMark06", "Thank you for registering") WinWaitActive("3DMark06", "Thank you for registering") Send("{ENTER}") EndFunc ;==>_RegisterThe code above might work for you, but there are some places where it could fail:WinWaitActive("Please Register")Sleep(8000)Send("{tab}") Hard coding a Sleep of 8 seconds in not a good idea, but you need something to make the script wait until the field is ready to take the "key code". Another loop might work best:DoSleep(100)Until ControlCommand("Please Register", "", controlID, "IsEnabled", "")Use the "AutoIt Window Info" tool to get the Control ID of the field of interest.[That Do/Until loop above and the Control... functions below might not work for all applications, but I have to mentioned them, in case they do work :-]The Do/Until loop above replaces all of this:WinWait("Please Register")WinActivate("Please Register")WinActivate("Please Register")WinActivate("Please Register")WinWaitActive("Please Register")Sleep(8000)After the field is ready for the "key code" you might want to useControlSetText("Please Register", "", controlID, "xxxx-xxxx-xxxx-xxxx-xxxx-xxxx")You will not have to tab to the field if you use ControlSetText or ControlSend and the window does not have to be active.After getting the "key code" in the field, use ControlClick to replace those tabs and the Enter that you sent.By now, you should be getting the picture.Post back if some part of it does not work for you. [size="1"][font="Arial"].[u].[/u][/font][/size] 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