Multiple #IF, and also toggle. how to script Topic is solved

Ask gaming related questions (AHK v1.1 and older)
s_adavan
Posts: 62
Joined: 10 Nov 2020, 06:31

Multiple #IF, and also toggle. how to script

Post by s_adavan » 26 Jun 2022, 00:29

have changed this many times and can't seem to get it works.

and now have reached my wit's end.

how is multiple #IF like this supposed to be written?

Code: Select all

Gosub, ~\
Return

#IFWinActive, ahk_exe PillarsOfEternityII.EXE						;PoE2 [Active] and Numlock [On] 
NumpadClear::	b											;remap, b									
#IF

~\::														;Toggle-Key, \
	NNLState := !GetKeyState("NumLock","T")					
	GetKeyState, NumState, NumLock, T
	If NumState = D
	{
	Progress, B1 Y80 ZH0 fs9 H25 W110 CTFFFFFF CW000000 Hide, Battle Mode, , text popup, Georgia
	DetectHiddenWindows, On
	WinSet, Transparent, 150, text popup
	Progress, Show
	Sleep, 200
	}
	else
	{
	Progress, Off
	Sleep, 200
	}
	return		
	
#IF WinActive("ahk_exe PillarsOfEternityII.EXE") && NNLState 			;PoE2 [Active] and Numlock [Off]		
	NumpadClear::	Down									;remap, down arrow
#IF

Rohwedder
Posts: 7554
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Multiple #IF, and also toggle. how to script

Post by Rohwedder » 26 Jun 2022, 01:14

Hallo,
your use of the #Ifs is fine. Whether this use here is purposeful for you depends on the desired function of this script. I don't know this desired function. I only see the function which the script has right now.

s_adavan
Posts: 62
Joined: 10 Nov 2020, 06:31

Re: Multiple #IF, and also toggle. how to script

Post by s_adavan » 26 Jun 2022, 01:58

Hello Rohwedder.. thank you for the response.

I see.. but for some reasons it's not working here.

I've make it simpler below for testing, on microsoft word.

Code: Select all

Gosub, ~\
Return

#IfWinActive, ahk_exe WINWORD.EXE						;TOGGLE ON (Numstate On & WinWord)
NumpadClear::	Send, On																
#IF

~\::										;TOGGLE	KEY
	NNLState := !GetKeyState("\","T")					
	GetKeyState, NumState, \, T
	If NumState = D
	{
	Progress, B1 Y80 ZH0 fs9 H25 W110 CTFFFFFF CW000000 Hide, Battle Mode, , text popup, Georgia
	DetectHiddenWindows, On
	WinSet, Transparent, 150, text popup
	Progress, Show
	}
	else
	{
	Progress, Off
	}
	return		
	
#IF WinActive("ahk_exe WINWORD.EXE") && NNLState 				;TOGGLE OFF (Numstate Off & WinWord)				
NumpadClear::	Send, Off							
#IF
When / toggle is [on] and MicorsoftWord [active], NumpadClear send 'on'.
When / toggle is [off] and MicrosoftWord [active], NumpadClear send 'off'.

I tried it here, but always get the 'on', the toggle has no effect.
There is nothing impossible to him who will try. -Alexander the Great-

Rohwedder
Posts: 7554
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Multiple #IF, and also toggle. how to script

Post by Rohwedder » 26 Jun 2022, 02:46

Try:

Code: Select all

Gosub, ~\
Return
#If WinActive("ahk_exe WINWORD.EXE")
Numpad5::	Send, On 	; (NumLockState On & WinWord)
NumpadClear::	Send, Off	; (NumLockState Off & WinWord)
#IF

~\::
SetNumLockState,% NNLState := !NumState := GetKeyState("NumLock", "T")
; Toggles: NumLockState: On/Off, NNLState: False/True, NumState: True/False 
If NumState
{
	Progress, B1 Y80 ZH0 fs9 H25 W110 CTFFFFFF CW000000 Hide, Battle Mode, , text popup, Georgia
	DetectHiddenWindows, On
	WinSet, Transparent, 150, text popup
	Progress, Show
}
else
{
	Progress, Off
}
return
https://www.autohotkey.com/docs/KeyList.htm#numpad

s_adavan
Posts: 62
Joined: 10 Nov 2020, 06:31

Re: Multiple #IF, and also toggle. how to script

Post by s_adavan » 26 Jun 2022, 04:59

Hello Rohwedder.. thanks. I see.. yes that works.

Sorry if too many questions :oops: (hopefully, this is the last one)
As NumpadClear & Numpad5 is on the same single button,
how about other buttons that does not have an alternate, such as =, *, backspace, etc.

For example:
When \ toggle is [on] and MicrosoftWord [active], = send 'on'.
When \ toggle is [off] and MicrosoftWord [active], = send 'off'.

If I put it like below, surely it's not the way to go, because it has become an 'Error: Duplicate hotkey'.

Code: Select all

Gosub, ~\
Return
#If WinActive("ahk_exe WINWORD.EXE")
=::	Send, On 	; (NumLockState On & WinWord)
=::	Send, Off	; (NumLockState Off & WinWord)
#IF

~\::
SetNumLockState,% NNLState := !NumState := GetKeyState("NumLock", "T")
; Toggles: NumLockState: On/Off, NNLState: False/True, NumState: True/False 
If NumState
{
	Progress, B1 Y80 ZH0 fs9 H25 W110 CTFFFFFF CW000000 Hide, Battle Mode, , text popup, Georgia
	DetectHiddenWindows, On
	WinSet, Transparent, 150, text popup
	Progress, Show
}
else
{
	Progress, Off
}
return
how would it be written in this case, is it something possible?

Previously I run the toggle script (numlock) without the WinActive, and it works just fine.
after adding the WinActive, I'm at lost wrapping my head around this whole concept of #if, toggle, numlock, numstate, etc.
it's totally on another level of complexity.
There is nothing impossible to him who will try. -Alexander the Great-

Rohwedder
Posts: 7554
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Multiple #IF, and also toggle. how to script  Topic is solved

Post by Rohwedder » 26 Jun 2022, 06:52

Then:

Code: Select all

Gosub, ~\
Return
#If WinActive("ahk_exe WINWORD.EXE") And NumState
=::	Send, On 	; (NumLockState On & WinWord)
#If WinActive("ahk_exe WINWORD.EXE") And NNLState
=::	Send, Off	; (NumLockState Off & WinWord)
#IF
~\::
SetNumLockState,% NNLState := !NumState := GetKeyState("NumLock", "T")
; Toggles: NumLockState: On/Off, NNLState: False/True, NumState: True/False 
If NumState
{
	Progress, B1 Y80 ZH0 fs9 H25 W110 CTFFFFFF CW000000 Hide, Battle Mode, , text popup, Georgia
	DetectHiddenWindows, On
	WinSet, Transparent, 150, text popup
	Progress, Show
}
else
{
	Progress, Off
}
return
or:

Code: Select all

Gosub, ~\
Return
#If WinActive("ahk_exe WINWORD.EXE")
=::	Send,% NumState ? "On" : "Off"
#IF
~\::
SetNumLockState,% NNLState := !NumState := GetKeyState("NumLock", "T")
; Toggles: NumLockState: On/Off, NNLState: False/True, NumState: True/False 
If NumState
{
	Progress, B1 Y80 ZH0 fs9 H25 W110 CTFFFFFF CW000000 Hide, Battle Mode, , text popup, Georgia
	DetectHiddenWindows, On
	WinSet, Transparent, 150, text popup
	Progress, Show
}

s_adavan
Posts: 62
Joined: 10 Nov 2020, 06:31

Re: Multiple #IF, and also toggle. how to script

Post by s_adavan » 26 Jun 2022, 22:29

Hello Rohwedder..

Yes...! I think that's it!!

though seems that all the 'NNLState' got the other way round with the 'NumState', but that's a very small matter.

Thanks a lot
heel erg bedankt :D

Just now, I was thinking of something more primitive like below. But of course your script is the better way :D

Code: Select all

#If WinActive("ahk_exe WINWORD.EXE")
$\::						
	if (Toggle := !Toggle)	
	{
	Send, {\ Down}	
	Progress, B1 Y80 ZH0 fs9 H25 W110 CTFFFFFF CW000000 Hide, Battle Mode, , text popup, Georgia
	DetectHiddenWindows, On
	WinSet, Transparent, 150, text popup
	Progress, Show
	}		
	else
	{
	Send, {\ Up}	
	Progress, Off	
	}			
	Return
	
\ & =::	Send, On 	; (\ Down & WinWord)
=::	Send, Off	; (\ Up Off & WinWord)

#IF	
There is nothing impossible to him who will try. -Alexander the Great-

s_adavan
Posts: 62
Joined: 10 Nov 2020, 06:31

Re: Multiple #IF, and also toggle. how to script

Post by s_adavan » 27 Jun 2022, 03:19

Hello Rohwedder..

I have a small problem, I just noticed:
whenever the script started, it will automatically have the numlock set to 'On', and I have to turn it off manually.

I could not figure how to solve this.

Below is another old 'numlock' script that I use, this one does not have that problem.

Code: Select all

Gosub, ~NumLock
Return

~NumLock::
			NNLState := !GetKeyState("NumLock","T")					
			GetKeyState, NumState, NumLock, T
			If NumState = D
			{
			Progress, B1 Y140 fs9 zh0 W200 CWFFFFFF, `nNumlock State is toggled ON.`n, ,text popup, Segoe UI
			DetectHiddenWindows, On
			WinSet, Transparent, 210, text popup
			Progress, Show
			}
			else
			{			
			Progress, Off
			}
			return
There is nothing impossible to him who will try. -Alexander the Great-

Rohwedder
Posts: 7554
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Multiple #IF, and also toggle. how to script

Post by Rohwedder » 27 Jun 2022, 03:51

Then:

Code: Select all

Loop, 2 ;<<<<<<<<<<
	Gosub, ~\
Return
#If WinActive("ahk_exe WINWORD.EXE") And NumState
=::	Send, On 	; (NumLockState On & WinWord)
#If WinActive("ahk_exe WINWORD.EXE") And NNLState
=::	Send, Off	; (NumLockState Off & WinWord)
#IF
~\::
SetNumLockState,% NNLState := !NumState := GetKeyState("NumLock", "T")
; Toggles: NumLockState: On/Off, NNLState: False/True, NumState: True/False 
If NumState
{
	Progress, B1 Y80 ZH0 fs9 H25 W110 CTFFFFFF CW000000 Hide, Battle Mode, , text popup, Georgia
	DetectHiddenWindows, On
	WinSet, Transparent, 150, text popup
	Progress, Show
}
else
{
	Progress, Off
}
return

s_adavan
Posts: 62
Joined: 10 Nov 2020, 06:31

Re: Multiple #IF, and also toggle. how to script

Post by s_adavan » 27 Jun 2022, 04:43

Oh, yes it works.
Thank you very much :D
There is nothing impossible to him who will try. -Alexander the Great-

Post Reply

Return to “Gaming Help (v1)”