Jump to content
Sign in to follow this  
Canasian

Script won't stay running? What did I do wrong?

Recommended Posts

Canasian

This is my simple code. I want to be able to start it.. and have it just sit there and not do anything until i push the home key.. i can't get it to work tho.. when i load it it just flashes the taskbar icon and does nothing. I know i have to be missing something very small.. can anyone help me out plz?

program is just set as example.

HotKeySet("{HOME}","Loadit")

Func Loadit() 
    Run("program")
If  WinActive("program") Then
    Do 
        Sleep()
    Until
    WinActive("program") = False
EndIf
WinActivate("other program")
EndFuncoÝ÷ Øëaz»ajx­p¢¹"­jY]¡ë"¶Z(¸ Ò-Â)ej趦jwb}¬"Ú0uçâçb±§-÷¢·¥¢¶éí[az趦¬k²¶§iËb½æ§¢Ø^¯§v-«b²h§h³yÒ,¶«zÊ&zØbajÛ-jwl~âø§Ü¥¢R¢é]v®¶­sbb33c´ÄÒ÷D¶W6WBgV÷C·´ôÔWÒgV÷C²ÂgV÷C´ÆöFBgV÷C² ¤Fò 6ÆVWæfæG VçFÂb33c´ÄÒG'V

at the top of my script to keep it active eh.. there's probably a better way tho.. hm.... but even using that my script doesn't work how it should ^_^ sigh. i suck at this lol

Edited by Canasian

Share this post


Link to post
Share on other sites
bo8ster

Try using WinWaitActive to wait for the program to load.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites
herewasplato

no - it does not look right.

Sleep()

Until

You need a loop above or below the func

edit: see the sample script under HotKeySet in the help file

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
herewasplato

...

$LI = HotKeySet("{HOME}","Loadit")

Do 
    Sleep(infinity) 
    Until $LI = True

...

There is no need for a long sleep - one second or one year would work the same in this code:

HotKeySet("{HOME}","Loadit")

While 1

Sleep(1000)

Wend

Func Loadit()

;

EndFunc


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
Canasian

There is no need for a long sleep - one second or one year would work the same in this code:

HotKeySet("{HOME}","Loadit")

While 1

Sleep(1000)

Wend

Func Loadit()

;

EndFunc

Thanks a lot herewasplato ^_^ That worked ;) Now i need help with the actual function.. grr.. How do you make it wait until the window is NOT active or does not exist? I tried doing it as = false but that doesn't work eh? or = 2? what am i doing wrong?

Or i could go about this another approach. Is there a way to be in a full screen mode.. then run a program in the background without ever exiting fullscreen mode? because if you run something while in fullscreen mode it's going to kick you out of fullscreen correct?

HotKeySet("{HOME}", "Loadit")

While 1
    Sleep(1000)
WEnd

Func Loadit()
    Run("program")
    If WinWaitActive("program") Then
        Do
            Sleep(1000)
        Until WinExists("program") = False
        WinActivate("other program")
    EndIf
EndFunc

Share this post


Link to post
Share on other sites
oMBRa

Until WinExists("program") = 0

WinExist return 1 if the window exists, otherwise 0

Edited by oMBRa

Share this post


Link to post
Share on other sites
herewasplato

You are welcome.

Don't take this the wrong way, but you might want to read the help file. I don't mean search thru it looking for something, I mean read it like a book. Not that I've done that in a very long time, but I did it when I first started. There were plenty of things that I did not understand (and still don't) but that did not stop me from learning a lot. You might enjoy the ideas that come to mind as you read it. I'm not telling you to stop posting questions or anything like that - I'm just saying that you might enjoy the read.

> How do you make it wait until the window is NOT active or does not exist?

WinWaitClose

Pauses execution of the script until the requested window does not exist.

WinWaitNotActive

Pauses execution of the script until the requested window is not active.

>Is there a way to be in a full screen mode.. then run a program in the background without ever exiting fullscreen mode? because if you run something while in fullscreen mode it's going to kick you out of fullscreen correct?

That all depends on the programs that you are asking about.


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites
Canasian

Thank you very much Herewasplato.. You and Valuater have helped me more than you both should have.. haha I guess you're finally getting tired of it :( Of me asking questions that should be completely obvious lol.

And thank you Ombra ^_^ Your way worked but then herewasplato presented me with WinWaitClose :D

The script works perfectly and does exactly what i want it to now.. thanks so much guys. I suck lol.

HotKeySet("{HOME}", "Loadit")
HotKeySet("{ESC}", "Close")

While 1
    Sleep(1000)
WEnd

Func Loadit()
    Run("Program1")
    If WinWaitActive("Program1") Then
        Do
            Sleep(1000)
        Until WinWaitClose("Program1")
        Do
            Sleep(1000)
            WinActivate("Program2")
        Until WinActive("Program2")
    EndIf
EndFunc

Func Close()
    Exit
EndFunc

You are welcome.

Don't take this the wrong way, but you might want to read the help file. I don't mean search thru it looking for something, I mean read it like a book. Not that I've done that in a very long time, but I did it when I first started. There were plenty of things that I did not understand (and still don't) but that did not stop me from learning a lot. You might enjoy the ideas that come to mind as you read it. I'm not telling you to stop posting questions or anything like that - I'm just saying that you might enjoy the read.

Haha.. I wish helpfile had a hardcopy for sale :D I'd buy it and read it all the time at school.. guess i should print it out.. wow.. you really read everything in the helpfile like as a book when you first started?

> How do you make it wait until the window is NOT active or does not exist?

WinWaitClose

Pauses execution of the script until the requested window does not exist.

WinWaitNotActive

Pauses execution of the script until the requested window is not active.

Thank you that helped a lot ;)

>Is there a way to be in a full screen mode.. then run a program in the background without ever exiting fullscreen mode? because if you run something while in fullscreen mode it's going to kick you out of fullscreen correct?

That all depends on the programs that you are asking about.

say a looping batch file for example? or command prompt.

Share this post


Link to post
Share on other sites
herewasplato

You are welcome.

> I guess you're finally getting tired of it

Nope - that was not the impression that I wanted to convey.

If I don't want to answer a post - I just skip it :-)

Does this do the same thing for you? I should be able to tell just by looking at the code, but it is 4AM here and I've been up all night. That and I'm a senile old man.

HotKeySet("{HOME}", "Loadit")
HotKeySet("{ESC}", "Close")

While 1
    Sleep(1000)
WEnd

Func Loadit()
    Run("Program1")
    WinWait("Program1")
    WinWaitClose("Program1")
    
    WinWait("Program2")
    WinActivate("Program2")
    WinWaitActive("Program2")
EndFunc   ;==>Loadit

Func Close()
    Exit
EndFunc   ;==>Close

> I wish helpfile had a hardcopy for sale ^_^ I'd buy it and read it all the time at school..

Fortunately, I'm always around a computer. I just read it as a chm file. I had converted other chm files into files for iSilo for Palm PDA.

> you really read everything in the helpfile like as a book when you first started?

yep - just like I did the first DOS manual that I got my hands on.

It took me a long time to grasp the abstract concept of a folder (directory) tree structure as that manual presented it.

On the full screen question - the background process could be in a hidden window - especially a cmd prompt window. That should not bother a full screen app.

And then there are Virtual Machines

http://www.microsoft.com/windows/products/...pc/default.mspx

http://www.virtualbox.org/

Both are free - you just need a legal operating system license for each VM.

Then you could run an app and/or script in the "background".


[size="1"][font="Arial"].[u].[/u][/font][/size]

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.