Jump to content

3 If's Help please


uber125
 Share

Recommended Posts

I can't get this to work properly, only the one at the top seems to wonk right...

how do I get all of them to work? Not just the one on top.

If (WinWaitClose("notepad","")) Then call(Close()); Closes the script when window has been closed. 
If (WinWaitActive("notepad", "")) Then call (TerminateNReload());Relod the script when the window is active again. 
If (WinWaitNotActive("notepad", "")) Then call (Unbind());Unbind keys when ever the window becomes inactive.

I've also tried, with no success, this.

If (WinWaitClose("World of Warcraft","")) Then 
    call(Close()); Closes the script when window has been closed.
Elseif (WinWaitActive("World of Warcraft", "")) Then 
    call (TerminateNReload());Relod the script when the window is active again.
Elseif (WinWaitNotActive("World of Warcraft", "")) Then 
    call (Unbind());Unbind keys when ever the window becomes inactive.
EndIf

Func Unbind(); Unbind keys
    HotkeySet (@HotKeyPressed)
    Send (@HotKeyPressed)
    HotKeySet("{1}")
    HotKeySet("{2}")
    HotKeySet("{3}")
    HotKeySet("{4}")
    HotKeySet("{5}")
    HotKeySet("{ENTER}", "TerminateNReload")
EndFunc

Func TerminateNReload(); TerminateNReload the Script
    HotkeySet (@HotKeyPressed,"TerminateNReload")
    HotkeySet (@HotKeyPressed)
    Send(@HotKeyPressed)
    ShellExecute("test.au3","","","Run")
    Exit 0
    HotKeySet("{ENTER}", "Unbind")
EndFunc

Func Close()
    Exit 0
EndFunc

What am I missing???

Link to comment
Share on other sites

I can't get this to work properly, only the one at the top seems to wonk right...

how do I get all of them to work? Not just the one on top.

If (WinWaitClose("notepad","")) Then call(Close()); Closes the script when window has been closed. 
If (WinWaitActive("notepad", "")) Then call (TerminateNReload());Relod the script when the window is active again. 
If (WinWaitNotActive("notepad", "")) Then call (Unbind());Unbind keys when ever the window becomes inactive.

I would take a guess that if the first line is true, and the script terminates, any further lines won't be executed..

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

ok, but why would it be closing if notepad is running, just not active?

I've changed notepad to Untitled - Notepad, and it is working properly, the other 2 lines still don't work.

Is this because the 1st line is waiting to complete? If so, what can I do about it?

If (WinWaitClose("Untitled - Notepad","")) Then call(Close()); Closes the script when window has been closed.
If (WinWaitActive("Untitled - Notepad", "")) Then call (TerminateNReload());Relod the script when the window is active again.
If (WinWaitNotActive("Untitled - Notepad", "")) Then call (Unbind());Unbind keys when ever the window becomes inactive.
Edited by uber125
Link to comment
Share on other sites

There are a lot of problems I see in your script. It also appears to be incomplete. Here's my guess at what you are trying to actually do.

It looked like you wanted hotkeys to be registered only when the game was open, and unregistered when the game was minimized or something.

Global $keysregistered = False

While 1
    If Not WinExists("World of Warcraft") Then Exit
    If WinActive("World of Warcraft") And Not $keysregistered Then
        Bind()
    ElseIf Not WinActive("World of Warcraft") And $keysregistered Then
        Unbind()
    EndIf
    Sleep(100)
WEnd

Func Bind()
    $keysregistered = True
    ; register all your hotkeys here
    HotKeySet("1", "Whatever")
    HotKeySet("2", "Whatever2")
    ;...
EndFunc

Func Unbind()
    $keysregistered = False
    ; unregister all your hotkeys here
    HotKeySet("1") ; keys like 1 don't need {}
    HotKeySet("2")
    HotKeySet("3")
    HotKeySet("4")
    HotKeySet("5")
    HotKeySet("{ENTER}")
EndFunc

The TerminateNReload function was utter nonsense. I have no idea what you meant to do with it.

Edited by Richard Robertson
Link to comment
Share on other sites

I'm not sure what you mean by Adlib coding.

If you're talking about something like this.

Func myadlib()
    If (WinWaitActive("Untitled - Notepad", "")) Then call (TerminateNReload())
        ;...
    EndIf
EndFunc

It's doesn't work. I keep getting errors saying EndIf has no If.

Well no, that's not what I meant, but since I didn't provide an example of what I did mean, no worry..

For me to actually write the example code would've taken longer than most of us have left, anywhere.. but it seems others have provided some help and most probably better help than I could ever give..

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

Well no, that's not what I meant, but since I didn't provide an example of what I did mean, no worry..

For me to actually write the example code would've taken longer than most of us have left, anywhere.. but it seems others have provided some help and most probably better help than I could ever give..

Well, I thank you for trying snowmaker.

Richard Robertson, I'm working with your example, I'll let you know how it goes.

Link to comment
Share on other sites

I'm not sure what you mean by Adlib coding.

If you're talking about something like this.

Func myadlib()
    If (WinWaitActive("Untitled - Notepad", "")) Then call (TerminateNReload())
        ;...
    EndIf
EndFunc

It's doesn't work. I keep getting errors saying EndIf has no If.

I went a slightly different route than Richard, but you get almost the same result. I used notepad for my testing because I don't have WOW installed. Try out mine(replacing the references to notepad with ones to WOW) or Richards and it should work for you.

Opt("WinTitleMatchMode", 2)

Global $keysregistered = False

ProcessWait ("notepad.exe")

While ProcessExists("notepad.exe")
    If WinActive("Notepad","") And Not $keysregistered Then
        Bind()
        WinWaitNotActive("Notepad","")
    ElseIf Not WinActive("Notepad","") And $keysregistered Then
        Unbind()
        WinWaitActive("Notepad","")
    EndIf
WEnd

Func Bind()
    ;MsgBox(0,"Test","Notepad window is ACTIVE")
    $keysregistered = True
    ; register all your hotkeys here
    HotKeySet("1", "Whatever")
    HotKeySet("2", "Whatever2")
    ;...
EndFunc

Func Unbind()
    ;MsgBox(0,"Test","Notepad window has LOST FOCUS")
    $keysregistered = False
    ; unregister all your hotkeys here
    HotKeySet("1") ; keys like 1 don't need {}
    HotKeySet("2")
    HotKeySet("3")
    HotKeySet("4")
    HotKeySet("5")
    HotKeySet("{ENTER}")
EndFunc
Link to comment
Share on other sites

There are a lot of problems I see in your script. It also appears to be incomplete. Here's my guess at what you are trying to actually do.

It looked like you wanted hotkeys to be registered only when the game was open, and unregistered when the game was minimized or something.

The TerminateNReload function was utter nonsense. I have no idea what you meant to do with it.

You version is working wonderfully. I just can't figure out how to unbind the keys when Enter is hit in game. Basically, I just want the script to become inactive, or "unbound", when the game is either minimized or the window is just inactive. Say if I'm using FireFox to look something up. Or, if I hit the Enter key (in game), then unbind the keys, and send {Enter} after it’s been unbound. then rebind when Enter is hit again (in game), and send {Enter} after it’s been rebound.

Also, just FYI the TerminateNReload function was added because sometimes the key binding would get mixed up from spamming. So that was the fastest way I could think of, to make sure everything was bound correctly. Just restart the script. You version doesn't seem to have that issue though.

func Chat(); Chat+Unbind
    HotKeySet("{ENTER}")
    Send ("{ENTER}")
    HotKeySet("{ENTER}", "Unbind"); Unbind+Send Enter
EndFunc

Func Bind()
    ; register all your hotkeys here
    HotKeySet("1", "Shot1")
    HotKeySet("2", "Shot2")
    HotKeySet("3", "Shot3")
    HotKeySet("4", "Melee")
    HotKeySet("5", "Mark")
    HotKeySet("{ENTER}", "Chat"); Bind+Send Enter
EndFunc

Func Unbind()
    ; unregister all your hotkeys here
    HotKeySet("1") ; keys like 1 don't need   
    HotKeySet("2")
    HotKeySet("3")
    HotKeySet("4")
    HotKeySet("5")
    HotKeySet("{ENTER}", "Bind"); Unbind+Send Enter

Will Send {Enter} but will not unbind/rebind.

entire script if you need it.

Dim $keysregistered = False

While 1
    If Not WinExists("Untitled - Notepad") Then Exit
    If WinActive("Untitled - Notepad") And Not $keysregistered Then
        Bind()
    ElseIf Not WinActive("Untitled - Notepad") And $keysregistered Then
        Unbind()
    EndIf
WEnd

func Shot1(); Shot1
    HotKeySet("1")
    Send ("8")
    Send ("1")    
EndFunc

func Shot2(); Shot2
    HotKeySet("2")
    Send ("q")
    Send ("w")
    Send ("e")    
EndFunc

func Chat(); Chat+Unbind
    HotKeySet("{ENTER}")
    Send ("{ENTER}")
    HotKeySet("{ENTER}", "Unbind"); Unbind+Send Enter
EndFunc

Func Bind()
    ; register all your hotkeys here
    HotKeySet("1", "Shot1")
    HotKeySet("2", "Shot2")
    HotKeySet("{ENTER}", "Chat"); Bind+Send Enter
EndFunc

Func Unbind()
    ; unregister all your hotkeys here
    HotKeySet("1") ; keys like 1 don't need   
    HotKeySet("2")
    HotKeySet("{ENTER}", "Bind"); Unbind+Send Enter
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...