Switch between toggles Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
philsi
Posts: 5
Joined: 08 Apr 2017, 04:50

Switch between toggles

12 Aug 2018, 08:23

Hi, i want to be able to switch between each toggle. Currently i press XButton2 to start the toggle and i would press XButton2 to stop the toggle, but i would like to also press XButton1 to break the Xbutton2 toggle and visa vera.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

swagfag
Posts: 949
Joined: 11 Jan 2017, 17:59

Re: Switch between toggles

12 Aug 2018, 09:19

youre misusing the timers and loops here. u tell a timer to run once, very nearly immediately, then enter an infinite loop right after. just.. dont do this.
what u need is a timer thats gonna tick every 80ms and run the send command once. To set it up, u first define the function that u want ur timers to carry out. Then make a bound function object out of it, storing it into a variable. U pass arguments to the function using the Bind() method. Finally u call the timer and point it to the bound function object that u had created.

Code: [Select all] [Download] GeSHi © Codebox Plus

send8 := Func("sendKey").Bind(8)
send9 := Func("sendKey").Bind(9)

#IfWinActive Gdk
XButton1::SetTimer % send8, % (timerToggle1 := !timerToggle1) ? "80" : "Off"
XButton2::SetTimer % send9, % (timerToggle2 := !timerToggle2) ? "80" : "Off"

sendKey(key) {
Send % key
}
philsi
Posts: 5
Joined: 08 Apr 2017, 04:50

Re: Switch between toggles

12 Aug 2018, 12:37

I tried your code but doesn't seem to switch between the timers. Basically i want to end one timer by activating another instead of having to turn the first one off with the same button (but also still want to turn them off by using the same button)

Example:

1. I press and release XButton1 which activates a timer that continuously presses key 9.
2. I press and release Xbutton2 which stops the first timer then activates a timer that continuously presses key 8.

And visa versa.
philsi
Posts: 5
Joined: 08 Apr 2017, 04:50

Re: Switch between toggles

15 Aug 2018, 08:43

Is this going to be possible?
swagfag
Posts: 949
Joined: 11 Jan 2017, 17:59

Re: Switch between toggles  Topic is solved

15 Aug 2018, 10:55

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

philsi
Posts: 5
Joined: 08 Apr 2017, 04:50

Re: Switch between toggles

15 Aug 2018, 20:56

Tried it again and it does work, thanks very much!

Return to “Ask For Help”

Who is online

Users browsing this forum: Scr1pter and 47 guests