youknowwho4eva Posted July 23, 2008 Share Posted July 23, 2008 I'm trying to make a simple script that sits in the background waiting for certain things, and if the program it interacts with closes, I want the script to exit. I've tried about 50,000 things from the help file (except the one that works) and did a search on here and didn't see anything helpful (probably there somewhere, I just didn't see it) But anyway here is what I have. How do I make it close when Kobutek KeyCreator closes? (the if was my latest way of trying, the script doesn't start if KeyCreator isn't open, but doesn't close when its closed. While 1 If WinExists("Kubotek KeyCreator") then $foo = MouseGetCursor() WinWaitActive("Kubotek KeyCreator") Select Case ControlgetFocus("Kubotek KeyCreator", "") = "AfxFrameOrView70u1" and $foo = 0 and WinActive ("Kubotek KeyCreator") Send ("{shiftdown}") MouseClick ("secondary") send ("{shiftup}") EndSelect Sleep(20) Else Exit EndIf WEnd Giggity Link to comment Share on other sites More sharing options...
TheSaint Posted July 23, 2008 Share Posted July 23, 2008 I'm trying to make a simple script that sits in the background waiting for certain things, and if the program it interacts with closes, I want the script to exit. I've tried about 50,000 things from the help file (except the one that works) and did a search on here and didn't see anything helpful (probably there somewhere, I just didn't see it) But anyway here is what I have. How do I make it close when Kobutek KeyCreator closes? (the if was my latest way of trying, the script doesn't start if KeyCreator isn't open, but doesn't close when its closed. While 1 If WinExists("Kubotek KeyCreator") then $foo = MouseGetCursor() WinWaitActive("Kubotek KeyCreator") Select Case ControlgetFocus("Kubotek KeyCreator", "") = "AfxFrameOrView70u1" and $foo = 0 and WinActive ("Kubotek KeyCreator") Send ("{shiftdown}") MouseClick ("secondary") send ("{shiftup}") EndSelect Sleep(20) Else Exit EndIf WEndIt may be that you need to use ProcessExists(), but I haven't looked too deeply into your code ... annoying to read without correct tabbing! muttley Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
Clipper34 Posted July 23, 2008 Share Posted July 23, 2008 Well heres my try at it. Hope this helps, Clipper34. While 1 If WinExists("Kubotek KeyCreator") Then WinWaitActive("Kubotek KeyCreator") If ProcessExists("KeyCreator process here") Then ProcessWaitClose("KeyCreator process here") Exit EndIf Func Exit_Func() ProcessWaitClose("KeyCreator process") Exit EndFunc If ProcessExists("KeyCreator process here") Not Then ProcessWait("KeyCreator process here") Call("Exit_Func") EndIf EndIf WEnd Link to comment Share on other sites More sharing options...
youknowwho4eva Posted July 23, 2008 Author Share Posted July 23, 2008 @ Clipper34, I tried just taking out your Exit_func, but unfortunatly that didnt work, I dont fully understand how to use the rest of it. @ TheSaint, Heres what I have now (fully tabbed), the ProcessExists just closed the script while KeyCreator was still running... so here is where I'm at now. While 1 $foo = MouseGetCursor() WinWaitActive("Kubotek KeyCreator") Select Case ControlgetFocus("Kubotek KeyCreator", "") = "AfxFrameOrView70u1" and $foo = 0 and WinActive ("Kubotek KeyCreator") Send ("{shiftdown}") Send ("{ctrldown}") MouseClick ("secondary") send ("{shiftup}") Send ("{ctrlup}") Case WinExists("Kubotek KeyCreator") Not Exit EndSelect Sleep(20) WEnd Func Exit_Func() ProcessWaitClose("KeyCreator process") Exit EndFunc Giggity Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 23, 2008 Moderators Share Posted July 23, 2008 While ProcessExists("KeyCreator process") ;Do my stuff WEnd Exit Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
FreeFry Posted July 23, 2008 Share Posted July 23, 2008 (edited) There's a few ways to go about this.Perhaps something like this:expandcollapse popup;Example 1 ( using WinExists ) Dim $sWindowClass = "[CLASS:Notepad]" Run("Notepad.exe"); Make sure it's running WinWait($sWindowClass); Wait for the window to exist Dim $hWindow = WinGetHandle($sWindowClass) While WinExists($hWindow) ; Do something WEnd ;Script will end here when window doesn't exist anymore ConsoleWrite("Example 1 Exit" & @LF) ;Example 2 ( using ProcessExists ) Dim $sProcessName = "notepad.exe" Run("Notepad.exe"); Make sure it's running While ProcessExists($sProcessName) ; Do something WEnd ;Script will end here when window doesn't exist anymore ConsoleWrite("Example 2 Exit" & @LF) ;Example 3( a combination of both, but using the adlib feature ) Dim $sWindowClass = "[CLASS:Notepad]" Dim $sProcessName = "notepad.exe" Run("Notepad.exe"); Make sure it's running ProcessWait($sProcessName) WinWait($sWindowClass); Wait for the window to exist Dim $hWindow = WinGetHandle($sWindowClass) Dim $iProcessID = ProcessExists($sProcessName) AdlibEnable("_CheckApp", 250); This will run the _CheckApp function every 250ms(0.25 seconds) While 1 ; Do something WEnd Func _CheckApp() If Not WinExists($hWindow) Or Not ProcessExists($iProcessID) Then ConsoleWrite("Example 3 Exit" & @LF) Exit EndIf EndFuncIt should be noted that even though I used the windows classname, it is not required, title should work fine too. muttleyEdit:Doh, Smoky made it before me. Changed to AutoIt tags Edited July 23, 2008 by FreeFry Link to comment Share on other sites More sharing options...
youknowwho4eva Posted July 23, 2008 Author Share Posted July 23, 2008 (edited) I tried dim $hWindow = WinGetHandle("Kobutek KeyCreator") While WinExists($hWindow) $foo = MouseGetCursor() WinWaitActive("Kubotek KeyCreator") Select Case ControlgetFocus("Kubotek KeyCreator", "") = "AfxFrameOrView70u1" and $foo = 0 and WinActive ("Kubotek KeyCreator") Send ("{shiftdown}") Send ("{ctrldown}") MouseClick ("secondary") send ("{shiftup}") Send ("{ctrlup}") EndSelect Sleep(20) WEnd Exit and While ProcessExists("KC.exe") $foo = MouseGetCursor() WinWaitActive("Kubotek KeyCreator") Select Case ControlgetFocus("Kubotek KeyCreator", "") = "AfxFrameOrView70u1" and $foo = 0 and WinActive ("Kubotek KeyCreator") Send ("{shiftdown}") Send ("{ctrldown}") MouseClick ("secondary") send ("{shiftup}") Send ("{ctrlup}") EndSelect Sleep(20) WEnd Exit No luck... The program works and everything, it just doesn't close when KeyCreator does... I dont see what I'm doing wrong. I even checked the process manually (alt ctrl delete) and KC.exe was not on the list... Edited July 23, 2008 by youknowwho4eva Giggity Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 23, 2008 Moderators Share Posted July 23, 2008 WinWaitActive() ... get rid of it. Make it a conditional statement instead. While ProcessExists("KC.exe");Funny how the name keeps changing If WinActive("Kubotek KeyCreator") Then ;Select etc EndIF Sleep(10) WEnd Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
youknowwho4eva Posted July 23, 2008 Author Share Posted July 23, 2008 muttley Happy day. Thank you all much, that did it SmOke_N. And the name kept changing as I would have to jump to the help file to see which was needed for which command I probably got it wrong 100 times but it works now. Thought my head was going to explode, tried all the stuff and it still didn't work, all cause that one command. Giggity Link to comment Share on other sites More sharing options...
cal Posted July 24, 2008 Share Posted July 24, 2008 I'm trying to make a simple script that sits in the background waiting for certain things, and if the program it interacts with closes, I want the script to exit. You just described 80% of my stuff. Glad you figured it out but here is something in my default template whenever I start working on something. code to get some program going. are_we_done('someprocessname.exe', 5) more code for whatever setup to do kotkeys and so forth. While 1 Sleep(30000) WEnd Func are_we_done($process_name2,$timout_value) Global $process_name = '' $process_name = $process_name2 AdlibEnable("are_we_done_2", $timout_value * 1000) EndFunc ;==>are_we_done Func are_we_done_2() $pid = ProcessExists($process_name) If $pid == 0 Then Exit EndFunc Basically the bottom stuff is copied as is to my scripts and I just change the "are_we_done" line with the process I want to look for. Notice its using the AdlibEnable command to keep checking if the program we are working with is still running (once every 5 seconds in this case). That way I don't have to keep checking for it in my main code. And if there is an error in my code that cause it to get stuck. Then adlibenable will still work and the script will still exit. 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