Schoening Posted January 9, 2012 Share Posted January 9, 2012 Hey, so i started Learning AutoIt yesterday.. and after reading, testing (Lots of infinte {Tab} Loops ) I figured that i need help, because this stuff still is somewhat out of my LeaugeSo the idea is that the Script should check if the Application is Running, If not, Exit -(That part works 50%, but does not Exit when i quit the Application after i launch the Script - Not the Main Issue though)And Do the Function every time i press "W"HotKeySet("{w}", "Poof") MsgBox(0,"Running","Running") ;MessageBox Informing that the Script is Running WinActivate("Application") ;Changes to the "Application" Window WinActive("Application") ; Runs Until "Aplication" is Closed While WinActive("Application") Sleep (100) WEnd Func Poof() ;When User Presses W Do: Send("{w}") MouseClick("left") Send("{tab}") Sleep(1) Send("{w}") MouseClick("left") Send("{tab}") Sleep(1) Send("{w}") MouseClick("left") Send("{tab}") Sleep(1) Send("{w}") MouseClick("left") Send("{tab}") EndFunc MsgBox(0,"Not Running","Not Running") ; Informs that the "Application" is no longer RunningWhen i launch the script, i can't even Use the W key while the Script is Running.I have also tried IF THEN Statements:Func Poof() If StringInStr("{w}","{w}") Then And Func Poof() If StringInStr("@HotKeyPressed","{w}") ThenAfter 1 min or so, the script will exit to prevent overflow: " Recursion level has been exceeded"Ive looked it up and "That usually means you have a logical loop where a function is calling itself."While i kinda get it.. (This is pretty much the first time i am programming) I think it means i am building the whole script wrong.Any idea what i can do so it will do my function every time i press W , and how to prevent the Overflow? Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 9, 2012 Moderators Share Posted January 9, 2012 Hi, Schoening. To begin with, if you're wanting to use "w" for your hotkey, take out the {}. Ex.: HotKeySet("w", "Poof") Func Poof() MsgBox(0, "", "Bye") Exit EndFunc "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
AdamUL Posted January 9, 2012 Share Posted January 9, 2012 (edited) To continue with what JLogan3o13 was staying, change the "{w}" to "w" in your Send as well.Try thisHotKeySet("w", "Poof") MsgBox(0,"Running","Running") ;MessageBox Informing that the Script is Running WinActivate("Application") ;Changes to the "Application" Window WinActive("Application") ; Runs Until "Aplication" is Closed While WinActive("Application") Sleep (100) WEnd Func Poof() ;When User Presses W Do: Send("w") MouseClick("left") Send("{tab}") Sleep(1) Send("w") MouseClick("left") Send("{tab}") Sleep(1) Send("w") MouseClick("left") Send("{tab}") Sleep(1) Send("w") MouseClick("left") Send("{tab}") EndFunc MsgBox(0,"Not Running","Not Running") ; Informs that the "Application" is no longer RunningAdam Edited January 9, 2012 by AdamUL Link to comment Share on other sites More sharing options...
Schoening Posted January 9, 2012 Author Share Posted January 9, 2012 (edited) Thx But it is still not doing what i want it to do...It is still not doing what i want it to do, The Function is Running but is only "Pressing the W Key" in the Application when i Hold down Shift.. And After Some Time .. It Overflows. Also.. the Function is just Looping .. It is supposed to stop after doing theSend("w") MouseClick("left") Send("{tab}") 4 Times..This is How the Script Looked Last It didnt run out of memoryMsgBox(0,"Running","Running") ;MessageBox Informing that the Script is Running WinActivate("Application") ;Changes to the "Application" Window WinActive("Application") ; Runs Until "Aplication" is Closed While WinActive("Application") Sleep (5000) Send("w") MouseClick("left") Send("{tab}") Send("w") MouseClick("left") Send("{tab}") Sleep(1) Send("w") MouseClick("left") Send("{tab}") Sleep(1) Send("w") MouseClick("left") Send("{tab}") WEnd MsgBox(0,"Not Running","Not Running") ; Informs that the "Application" is no longer RunningBut Obviously i cannot Control this... And it will just Loop it every 5 Seconds instead of when i Press a Key Edited January 9, 2012 by Schoening Link to comment Share on other sites More sharing options...
Schoening Posted January 9, 2012 Author Share Posted January 9, 2012 I GOT IT WORKING !The Problem was, that the "Application" used W itself, so i had to Bind another Key Instead Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 9, 2012 Moderators Share Posted January 9, 2012 (edited) Schoening,You are Sending the same key as you use for the HotKey - so each time you Send it you merely action the HotKey again. Try disabling the HotKey as you enter the function and then re-enabling it as you leave:expandcollapse popupHotKeySet("w", "Poof") MsgBox(0, "Running", "Running") ;MessageBox Informing that the Script is Running WinActivate("Application") ;Changes to the "Application" Window ; You need to wait until the window is active or you could never enter the loop below <<<<<<<<<<<<<<<<<<< WinWaitActive("Application") ; Runs Until "Aplication" is Closed While WinActive("Application") Sleep(100) WEnd Func Poof() ;When User Presses W Do: While WinActive("Application") HotKeySet("w") ; Disable HotKey <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Sleep(5000) Send("w") MouseClick("left") Send("{tab}") Send("w") MouseClick("left") Send("{tab}") Sleep(10) ; <<<<<<<<<<<<<<<<<<<<<<<<< What did I tell you about Sleep? Send("w") MouseClick("left") Send("{tab}") Sleep(10) Send("w") MouseClick("left") Send("{tab}") HotKeySet("w", "Poof") ; Re-enable HotKey <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< WEnd EndFunc ;==>Poof MsgBox(0, "Not Running", "Not Running") ; Informs that the "Application" is no longer RunningI have not tested it because I do not know what the "Application" might be - see it it works for you. M23Edit: I see you worked it out yourself - congratulations! Edited January 9, 2012 by Melba23 Added new text Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Schoening Posted January 9, 2012 Author Share Posted January 9, 2012 Thanks I Keep the sleep(10) in mind But my Script Seems to work better then Yours Melba, because yours Keeps Looping, while mine only triggers when i press "x" Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 9, 2012 Moderators Share Posted January 9, 2012 Schoening,You are quite correct. I ended up with a mixture of your various posts and left the While...Wend loop in the function - my apologies. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Schoening Posted January 9, 2012 Author Share Posted January 9, 2012 Np Great Forum ! Perhaps i can get one more question answered.. It is annoying to use While WinActive("Application") Because The Script Shuts Down When i Open Another window.. But i Cannot Get This To Work While ProcessExists("Application") Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 9, 2012 Moderators Share Posted January 9, 2012 Hi Schoening, since you're using Send commands, you're going to wreak havoc as soon as the focus leaves your application's window anyway. If you're looking to do this in the background, I would suggest looking into the ControlSend options in the Help file. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Schoening Posted January 9, 2012 Author Share Posted January 9, 2012 Hi Schoening, since you're using Send commands, you're going to wreak havoc as soon as the focus leaves your application's window anyway. If you're looking to do this in the background, I would suggest looking into the ControlSend options in the Help file. Ok, I will do that Thx I Just found a bigger Problem.. The Whole Script Only Works When the "Application" is in Windowed Mode... Else it just Jumps to MsgBox(0,"Not Running","Not Running") ; Informs that the "Application" is no longer Running Like When I am Not Running the "Application" at all 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