Toggle window transparant

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
pliev
Posts: 6
Joined: 11 Sep 2022, 14:20

Toggle window transparant

14 May 2024, 12:40

I would like to have a script that toggles a window transparant.

I tried something like this, but it doesn't work:

Code: Select all

dz := WinGetTransparant "A"
If (dz > 254) {
	WinSetTransparant 200, "A"
}
else {
	WinSetTransparant 255, "A"
}
The warning dialog says: The variable appears to never be assigned a value

Any help is appreciated
gregster
Posts: 9095
Joined: 30 Sep 2013, 06:48

Re: Toggle window transparant

14 May 2024, 12:50

You have a typo there. It's WinSetTransparent with an e towards the end, not ...rant

Same for WinGetTransparent. If you need a return value, you'll have to use the function syntax with parentheses, though:

Code: Select all

dz := WinGetTransparent("A")
pliev
Posts: 6
Joined: 11 Sep 2022, 14:20

Re: Toggle window transparant

14 May 2024, 13:48

Thanks gregster! I missed the typo

The code I have until now:

Code: Select all

MouseGetPos ,, &MouseWin
dz := WinGetTransparent(MouseWin)
If (dz := 255) {
	WinSetTransparent 200, "A"
	return
}
If (dz := 200) {
	WinSetTransparent 255, "A"
}
It does make the window transparent, but it doesn't remove transparancy lateron
What am I doing wrong? Thanks for your help
gregster
Posts: 9095
Joined: 30 Sep 2013, 06:48

Re: Toggle window transparant

14 May 2024, 13:54

For comparisons in expressions, use =, and not the assignment operator := (which wouldn't check but overwrite the value of the variable).
pliev
Posts: 6
Joined: 11 Sep 2022, 14:20

Re: Toggle window transparant

14 May 2024, 14:18

gregster wrote:
14 May 2024, 13:54
For comparisons in expressions, use =, and not the assignment operator := (which wouldn't check but overwrite the value of the variable).

Thank you very much, it works now.

Code: Select all

MouseGetPos ,, &MouseWin
dz := WinGetTransparent(MouseWin)
If (dz = 255) {
	WinSetTransparent 200, "A"
} else {
	WinSetTransparent 255, "A"
}

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: mikeyww and 44 guests