Sign in to follow this  
Followers 0
boogieoompa

Stupid Question

8 posts in this topic

I know someone is going to say "I got this right out of the help manual" but I looked and I don't see what I am doing wrong. Basically I want autoit to exit whenever I exit my app that I am using it for. But I don't know how to place the exit command since I already have a while loop running (that picks up hotkeys). I tried combing the two while statements if multiple ways (including an if winExists statment) Any suggestions?

Thanks ahead

;way 1___________________________________________________
While 1
WinWaitClose("Freecell")
Exit
Wend

While 1
HotKeySet("a", "Function_1")
Wend

;way2__________________________________________
While 1
If WinExists("Freecell") Then
      HotKeySet("a", "Function_1")
Else
      Exit
Endif

Wend

Share this post


Link to post
Share on other sites



Runwait???


 

Spoiler

shoot_zpsfd329d66.png
dontbelieveeverythingyouthink_zps0e1e900

Madness is the first step to understanding...

Share this post


Link to post
Share on other sites

Hi!

You should set the hotkey at the beginning. No Loop is needed around it.

So your script is necer interpreted as far as the start of the second loop, cause the first one is an infinite loop.

peethebee


vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvGerman Forums: http://www.autoit.deGerman Help File: http://autoit.de/hilfe vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

Share this post


Link to post
Share on other sites

Like this:

HotKeySet("a", "Function_1")

While 1
; put your code in here
;
;
;
If NOT WinExists("Freecell") Then Exit
WEnd

Func Function_1()
; put your code in here
;
EndFunc
That code layout should exit the script when the window goes away... later

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

Share this post


Link to post
Share on other sites

Thanks for all the input however I think I was a little unclear in how I asked the question. I need the while loop because of the way that I am sending over the hotkeys (so that they work with caps lock). I simplified the code I posted not expecting it to make a difference (sorry). Here is a more accurate representation of what I am doing.

Thanks

While 1
WinWaitActive("freecell")                  ;turns on hot keys
HotKeySet("a", "Function_1")

WinWaitNotActive("freecell");Turns off hotkeys by sending through windows
HotKeySet("a")

If NOT WinExists("Freecell") Then Exit

Wend

While 1
    Sleep(100)
WEnd

Share this post


Link to post
Share on other sites

Thanks for all the input however I think I was a little unclear in how I asked the question. I need the while loop because of the way that I am sending over the hotkeys (so that they work with caps lock). I simplified the code I posted not expecting it to make a difference (sorry). Here is a more accurate representation of what I am doing.

Thanks

While 1
WinWaitActive("freecell")                 ;turns on hot keys
HotKeySet("a", "Function_1")

WinWaitNotActive("freecell");Turns off hotkeys by sending through windows
HotKeySet("a")

If NOT WinExists("Freecell") Then Exit

Wend

While 1
    Sleep(100)
WEnd
There is no need for two While...WEnd loops.

While 1
   If WinWaitActive("freecell")                Then HotKeySet("a", "Function_1")
   If WinWaitNotActive("freecell") Then HotKeySet("a")
   If Not WinExists("Freecell") Then Exit
   Sleep (100)
 WEnd

Share this post


Link to post
Share on other sites

Thanks but it didn't seem to work. It doesn't appear to be registering the IF statments.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thanks but it didn't seem to work. It doesn't appear to be registering the IF statments.

Actually, it isn't the "If" statements. It is because "FreeCell" was not capitalized. Here is another script to try:

While 1
     $active = WinWaitActive ("FreeCell") 
         If $active = 1 Then HotKeySet ("a", "Function_1")
     $inactive = WinWaitNotActive ("FreeCell")
         If $inactive = 1 Then HotKeySet ("a")
         If Not WinExists ("FreeCell") Then Exit
     Sleep (100)
 WEnd
 
 Func Function_1()
     MsgBox (0, "", "Function 1")
 EndFunc
Edited by SerialKiller

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