how do i make it that when one section of my AutoHotkey script activates, the other deactivates

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
mindlessplague
Posts: 5
Joined: 09 May 2024, 22:13

how do i make it that when one section of my AutoHotkey script activates, the other deactivates

10 May 2024, 02:57

How can I ensure that when one section of my AutoHotkey script activates, the other deactivates, and vice versa? Additionally, how do I implement a hotkey (denoted as 'y') to toggle the entire script's functionality? Please adjust the provided AutoHotkey code, where 'a,d' and 's,w' keys are paired.

Code: Select all

#Requires AutoHotkey v2.0
*a:: {
	Static A := 0
	Send (A:=!A)?"{Blind}{a down}":"{Blind}{a up}"
	KeyWait "a"
}
*d:: {
	Static D := 0
	Send (D:=!D)?"{Blind}{d down}":"{Blind}{d up}"
	KeyWait "d"
}
*r:: {
	Static R := 0
	Send (R:=!R)?"{Blind}{r down}":"{Blind}{r up}"
	KeyWait "r"
}
*s:: {
	Static S := 0
	Send (S:=!S)?"{Blind}{s down}":"{Blind}{s up}"
	KeyWait "s"
}
*w:: {
	Static W := 0
	Send (W:=!W)?"{Blind}{w down}":"{Blind}{w up}"
	KeyWait "w"
}
User avatar
boiler
Posts: 17192
Joined: 21 Dec 2014, 02:44

Re: how do i make it that when one section of my AutoHotkey script activates, the other deactivates

10 May 2024, 03:46

Code: Select all

#Requires AutoHotkey v2.0
Top := 1
#HotIf Top
*a:: {
	Static A := 0
	Send (A:=!A)?"{Blind}{a down}":"{Blind}{a up}"
	KeyWait "a"
send 'aa'
}
*d:: {
	Static D := 0
	Send (D:=!D)?"{Blind}{d down}":"{Blind}{d up}"
	KeyWait "d"
}
#HotIf
*r:: {
	Static R := 0
	Send (R:=!R)?"{Blind}{r down}":"{Blind}{r up}"
	KeyWait "r"
}
y::global Top := !Top
#HotIf !Top
*s:: {
	Static S := 0
	Send (S:=!S)?"{Blind}{s down}":"{Blind}{s up}"
	KeyWait "s"
}
*w:: {
	Static W := 0
	Send (W:=!W)?"{Blind}{w down}":"{Blind}{w up}"
	KeyWait "w"
}
mindlessplague
Posts: 5
Joined: 09 May 2024, 22:13

Re: how do i make it that when one section of my AutoHotkey script activates, the other deactivates

10 May 2024, 04:17

dunno why but even when the y key is pressed to deactivate the script the d key remains active and when it is on it often makes it so when you press w the output would be s
@boiler
User avatar
boiler
Posts: 17192
Joined: 21 Dec 2014, 02:44

Re: how do i make it that when one section of my AutoHotkey script activates, the other deactivates

10 May 2024, 04:34

I made a mistake where I left a Send ‘aa’ line in there I had for testing. Did you remove that? I don’t see how it would cause what you are describing, but fix that first anyway.

The swap approach works, as this demonstrates:

Code: Select all

#Requires AutoHotkey v2.0
Top := 1
#HotIf Top
*a::MsgBox 'a'
*d::MsgBox 'd'
#HotIf
*r::MsgBox 'r'
y::global Top := !Top
#HotIf !Top
*s::MsgBox 's'
*w::MsgBox 'w'
mindlessplague
Posts: 5
Joined: 09 May 2024, 22:13

Re: how do i make it that when one section of my AutoHotkey script activates, the other deactivates

10 May 2024, 05:23

still breaks 50% of the time the switch around so w does s half the time
User avatar
boiler
Posts: 17192
Joined: 21 Dec 2014, 02:44

Re: how do i make it that when one section of my AutoHotkey script activates, the other deactivates

10 May 2024, 05:41

mindlessplague wrote: dunno why but even when the y key is pressed to deactivate the script the d key remains active
Not sure why you expected the d key not to be active. It deactivates the hotkey as you said you wanted. Now you want the key to become a dead key instead of returning to its normal function?

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Google [Bot], smrt1, VanVarden and 33 guests