Toggle related Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Potato

Toggle related

24 Sep 2017, 03:33

Code: Select all

F8::
    Toggle := !Toggle
    While Toggle{
	SetScrolllockState AlwaysOn
	Click
	Sleep 60000
    }
SetScrolllockState AlwaysOff
return
So I want Scroll lock to be an indicator of whether my toggled script is being toggled on or off.
This script is working for the first time I toggle it.
Toggle on, off, back on, and then it stays permanently on. need help x:
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Toggle related

24 Sep 2017, 05:01

See https://autohotkey.com/docs/commands/_M ... sPerHotkey 2
F8::
Toggle := !Toggle
SetScrolllockState AlwaysOn
While Toggle{
Click
Sleep 60000
}
SetScrolllockState AlwaysOff
return[/code]
Potato
Posts: 6
Joined: 24 Sep 2017, 06:24

Re: Toggle related

24 Sep 2017, 06:28

Code: Select all

toggle = 0
#MaxThreadsPerHotkey 2

F8::
    Toggle := !Toggle
    SetScrolllockState AlwaysOn
    While Toggle{
	Click
	Sleep 60000
    }
SetScrolllockState AlwaysOff
return
My bad, I did not post the full code. Here is the full code. I tried what you stated but it still had the same issue :/
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Toggle related

24 Sep 2017, 06:58

Try this:

Code: Select all

toggle = 0
#MaxThreadsPerHotkey 2

F8::
    Toggle := !Toggle
    SetScrolllockState AlwaysOn
    While Toggle{
	ToolTip % A_TickCount
    While Toggle && A_Index<=60
        Sleep 1000
    }
SetScrolllockState AlwaysOff
ToolTip
return
Potato
Posts: 6
Joined: 24 Sep 2017, 06:24

Re: Toggle related

24 Sep 2017, 08:06

Same thing happened with the scroll lock, but this time the click is gone @.@
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Toggle related

24 Sep 2017, 08:43

I replaced Click with ToolTip so you can see the tooltip is turned on and off.
I don't have ScrollLock led on my keyboard but it works fine with Capslock for me:

Code: Select all

toggle = 0
#MaxThreadsPerHotkey 2

F8::
    Toggle := !Toggle
    SetCapsLockState AlwaysOn
    While Toggle{
	Click
    While Toggle && A_Index<=60
        Sleep 1000
    }
SetCapsLockState AlwaysOff
return
Potato
Posts: 6
Joined: 24 Sep 2017, 06:24

Re: Toggle related

24 Sep 2017, 11:18

I tried what you posted, however same issue. After toggling a few times, the led is just permanently on
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Toggle related

24 Sep 2017, 13:36

Try this one, I modified it to accept more than 2 presses and react faster as well as don't run the code when it is about to disable:

Code: Select all

toggle = 0
#MaxThreadsPerHotkey 99

F8::
    If !(Toggle := !Toggle)
        return
    SetCapsLockState AlwaysOn
    While Toggle{
	Click
    While Toggle && A_Index<=600
        Sleep 100
    }
SetCapsLockState AlwaysOff
return
Potato
Posts: 6
Joined: 24 Sep 2017, 06:24

Re: Toggle related

25 Sep 2017, 07:23

the last code worked perfectly, thanks alot!
Potato
Posts: 6
Joined: 24 Sep 2017, 06:24

Re: Toggle related  Topic is solved

30 Sep 2017, 10:42

HotKeyIt wrote:Try this one, I modified it to accept more than 2 presses and react faster as well as don't run the code when it is about to disable:

Code: Select all

toggle = 0
#MaxThreadsPerHotkey 99

F8::
    If !(Toggle := !Toggle)
        return
    SetCapsLockState AlwaysOn
    While Toggle{
	Click
    While Toggle && A_Index<=600
        Sleep 100
    }
SetCapsLockState AlwaysOff
return
Hi, I don't understand the A_Index<=600 and Sleep 100 part, could you explain it to me?
User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
Contact:

Re: Toggle related

30 Sep 2017, 10:50

Don't have to worry about thread/loop interruptions with the following

Code: Select all

toggle = 0

F8::
    toggle := !toggle
    SetCapsLockState % (toggle ? "AlwaysOn" : "AlwaysOff")
    SetTimer, autoclick, 100
    SetTimer, autoclick, % (toggle ? "On" : "Off")
return

autoclick:
    Click
return
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: garry, marypoppins_1, mikeyww, Rohwedder, RussF and 159 guests