Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Make window transparent and click "through" it


  • Please log in to reply
12 replies to this topic
sam.reckoner
  • Members
  • 51 posts
  • Last active: Apr 06 2012 02:20 AM
  • Joined: 11 Oct 2007
I have a number of Windows neatly tiled and these are usually behind a large maximized window. Is there a way to make the maximized window (currently foreground ) transparent, such that when I next click on that window one of the the smaller tiled windows behind it is brought to the foreground? In other words, the click on the maximized window goes "through" it to the smaller window behind it.

Thanks in advance.

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
You could loop through all visible windows and check if the coordinates are inside it.
I'll wirte a snippet (as soon as I eat something :lol:).

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
Well you could make the larger top window transparent using WinSet, Transparent, N, WinTitle but you'd have to go down to 1 or 0 (invisible) I think to be able to click through it.

The easy way would be to temporarily hide the window using WinHide.

A little more difficult would be to find all of the positions for the background windows and then when you click the position of where a background window exists, the forground window could be made transparent and then the smaller background window would be brought to the front.

Just depends on exactly how you want to do it.

Posted Image

don't duplicate, iterate!


MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009

A little more difficult would be to find all of the positions for the background windows and then when you click the position of where a background window exists, the forground window could be made transparent and then the smaller background window would be brought to the front.

That's exactly what I had in mind.
The following code has been tested. Please report if it doesn't work for you.
[color=cornflowerblue]CONST_TRANSPARENCY[/color] := 100
[color=darkred]WS_VISIBLE[/color] := 0x10000000

Return

;====================================================

; "emergency" restore hotkey
F11:: WinSet, Transparent, 255, A

;====================================================

; set transparency to allow the next hotkey to work
F12:: WinSet, Transparent, %[color=cornflowerblue]CONST_TRANSPARENCY[/color]%, A

;====================================================

MButton:: ; tested with MButton
  WinGetActiveTitle, [color=red]activeTitle[/color]
  WinGet, [color=black]transValue[/color], Transparent, %[color=red]activeTitle[/color]%
  If ( [color=black]transValue[/color] <> [color=cornflowerblue]CONST_TRANSPARENCY[/color] ) ; transparency must have been set previously
    Return
  [color=orange]winList[/color] := GetWindowsByStyle( [color=darkred]WS_VISIBLE[/color] , "[color=olive]§[/color]" )
  MouseGetPos, [color=blue]mouseX[/color], [color=blue]mouseY[/color]
  Loop, Parse, [color=orange]winList[/color], [color=olive]§[/color]
  {
    If ( A_LoopField = "[color=green]Program Manager[/color]" ) OR ( A_LoopField = [color=red]activeTitle[/color] )
      Continue
    WinGetPos, [color=violet]winX[/color], [color=violet]winY[/color], [color=violet]winW[/color], [color=violet]winH[/color], %A_LoopField%
    [color=violet]winXX[/color] := [color=violet]winX[/color] + [color=violet]winW[/color]  ,  [color=violet]winYY[/color] := [color=violet]winY[/color] + [color=violet]winH[/color]
    If [color=blue]mouseX[/color] between %[color=violet]winX[/color]% and %[color=violet]winXX[/color]%
      If [color=blue]mouseY[/color] between %[color=violet]winY[/color]% and %[color=violet]winYY[/color]%
      {
        WinSet, Transparent, 255, %[color=red]activeTitle[/color]%
        WinActivate, %A_LoopField%
        Return
      }
  }
Return

;====================================================

; http://www.autohotkey.com/forum/viewtopic.php?p=336020#336020
GetWindowsByStyle(p_style,p_delim="|")
{
  WinGet, l_array, List
  Loop, %l_array%
  {
    WinGet, l_tmp, Style, % "ahk_id " l_array%A_Index%
    If (l_tmp & p_style)
    {
      WinGetTitle, l_tmp, % "ahk_id " l_array%A_Index%
      l_out .= ( l_out="" ? "" : p_delim ) l_tmp
    }
  }
  Return l_out
}

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


sam.reckoner
  • Members
  • 51 posts
  • Last active: Apr 06 2012 02:20 AM
  • Joined: 11 Oct 2007

That's exactly what I had in mind.
The following code has been tested. Please report if it doesn't work for you.


Thanks for your quick great work.

This works great except for a couple of things:

* It makes the Taskbar transparent and leaves it transparent.
* It seems to lock up the middle button. Is there a way to unbind the middle button after it is used. In other words, the script does not use the middle button unless the F12 key had previously been used. I think there is some logic for this in the loop where you check for the existing transparency, but I'm not sure.
* Is there a way to make this work for un-maximized windows that nonetheless obscure or partially obscure windows behind them?

Thanks again!

TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006

* It makes the Taskbar transparent and leaves it transparent.
* It seems to lock up the middle button.


Try this:
[color=cornflowerblue]CONST_TRANSPARENCY[/color] := 100
[color=darkred]WS_VISIBLE[/color] := 0x10000000

Return

;====================================================

; "emergency" restore hotkey
F11:: WinSet, Transparent, 255, A

;====================================================

; set transparency to allow the next hotkey to work
F12:: WinSet, Transparent, %[color=cornflowerblue]CONST_TRANSPARENCY[/color]%, A

;====================================================

[color=red]~[/color]MButton:: ; tested with MButton
  WinGetActiveTitle, [color=red]activeTitle[/color]
  WinGet, [color=black]transValue[/color], Transparent, %[color=red]activeTitle[/color]%
  If ( [color=black]transValue[/color] <> [color=cornflowerblue]CONST_TRANSPARENCY[/color] ) ; transparency must have been set previously
    Return
  [color=orange]winList[/color] := GetWindowsByStyle( [color=darkred]WS_VISIBLE[/color] , "[color=olive]§[/color]" )
  MouseGetPos, [color=blue]mouseX[/color], [color=blue]mouseY[/color]
  Loop, Parse, [color=orange]winList[/color], [color=olive]§[/color]
  {
    If ( A_LoopField = "[color=green]Program Manager[/color]" ) OR ( A_LoopField = [color=red]activeTitle[/color] )
      Continue
    WinGetPos, [color=violet]winX[/color], [color=violet]winY[/color], [color=violet]winW[/color], [color=violet]winH[/color], %A_LoopField%
    [color=violet]winXX[/color] := [color=violet]winX[/color] + [color=violet]winW[/color]  ,  [color=violet]winYY[/color] := [color=violet]winY[/color] + [color=violet]winH[/color]
    If [color=blue]mouseX[/color] between %[color=violet]winX[/color]% and %[color=violet]winXX[/color]%
      If [color=blue]mouseY[/color] between %[color=violet]winY[/color]% and %[color=violet]winYY[/color]%
      {
        WinSet, Transparent, 255, %[color=red]activeTitle[/color]%,, ahk_class Shell_TrayWnd
        WinActivate, %A_LoopField%
        Return
      }
  }
Return

;====================================================

; http://www.autohotkey.com/forum/viewtopic.php?p=336020#336020
GetWindowsByStyle(p_style,p_delim="|")
{
  WinGet, l_array, List
  Loop, %l_array%
  {
    WinGet, l_tmp, Style, % "ahk_id " l_array%A_Index%
    If (l_tmp & p_style)
    {
      WinGetTitle, l_tmp, % "ahk_id " l_array%A_Index%
      l_out .= ( l_out="" ? "" : p_delim ) l_tmp
    }
  }
  Return l_out
}

Posted Image

don't duplicate, iterate!


sam.reckoner
  • Members
  • 51 posts
  • Last active: Apr 06 2012 02:20 AM
  • Joined: 11 Oct 2007

* It makes the Taskbar transparent and leaves it transparent.
* It seems to lock up the middle button.



It works better. Thanks. I actually found something here:

<!-- m -->http://www.autohotke...topic33191.html<!-- m -->

so,

#SingleInstance, Force
DetectHiddenWindows, on
Hotkey, ~+^LButton, ClickThrough, On
Return

ClickThrough:
MouseGetPos, x, y, hwnd
;WinSet, AlwaysOnTop, On, ahk_id %hwnd%
WinSet, Transparent, 80, ahk_id %hwnd%
WinSet, ExStyle, +0x00000020, ahk_id %hwnd%
Sleep 1500
WinSet, ExStyle, -0x00000020, ahk_id %hwnd%
WinSet, Transparent, OFF, ahk_id %hwnd%
Return

This is crude in that you have on 1.5 seconds to click under the now-transparent active window, but it works well enough for non-maximized windows.

LiquidGravity
  • Members
  • 156 posts
  • Last active: Oct 11 2014 04:11 PM
  • Joined: 26 Jan 2009
You could do a WinSet Transparent and a Winset Region to temporarily make the window transparent and remove the area around the mouse in the active window. I made a program that could easily be modified to do this.

http://www.autohotke...pic.php?t=36066

sam.reckoner
  • Members
  • 51 posts
  • Last active: Apr 06 2012 02:20 AM
  • Joined: 11 Oct 2007

You could do a WinSet Transparent and a Winset Region to temporarily make the window transparent and remove the area around the mouse in the active window. I made a program that could easily be modified to do this.

http://www.autohotke...pic.php?t=36066


Your script is amazing, but I don't know enough to make the changes you suggest.

thanks.

Wicked - Guest
  • Guests
  • Last active:
  • Joined: --
There's an example script somewhere on this forum showing how to make windows unclickable.

I would believe it was written by SKAN, as he's the AHK god in my eyes... Lol.

I can't find it atm, but if it helps, the method it used was changing the transparency slightly and then applying a window property.



SKAN could probably dig it up. ;).

  • Guests
  • Last active:
  • Joined: --
Sry for the poor explaination, but by unclickable, I mean you literally clicked through it.

Wicked
  • Members
  • 504 posts
  • Last active: Nov 18 2018 02:17 AM
  • Joined: 07 Jun 2008
Logged in now, sorry.

Sure enough, I was right. It was SKAN that showed me this nifty code...

Gui -Caption +AlwaysOnTop +Border +LastFound 
ID := WinExist()
Gui, Add, Text,, This is a Layered Window
Gui, Show, W640 h480
WinSet, ExStyle, +0x80020, ahk_id %ID% ; See Note
WinSet, Transparent, 125, ahk_id %ID%
Return

#End::ExitApp
; Note: ( WS_EX_LAYERED:=0x00080000 ) Or ( WS_EX_TRANSPARENT:=0x20 )

This code taken from this thread.

Or, another solution from the same thread...

Gui  +AlwaysOnTop [color=red]+E0x20[/color] +LastFound
Gui1:=WinExist()
Gui, Add, Picture, x3 y5 Icon1, %A_AhkPath%
Gui, Font, s18 Bold, Tahoma
Gui, Add, Text, x+5 w270 h32 +0x201 c404040, AutoHotkey Rocks !!!
Gui, Show, HIDE NA   
WinSet Transparent, 150, ahk_id %Gui1%


Wicked
  • Members
  • 504 posts
  • Last active: Nov 18 2018 02:17 AM
  • Joined: 07 Jun 2008
Since I use this a lot... Surprisingly... I wrote it into a function:

/*
WinSet_Click_Through - Makes a window unclickable.

I - ID of the window to set as unclickable.

T - The transparency to set the window. Leaving it blank will set it to 254. It can also be set On or Off. Any numbers lower then 0 or greater then 254 will simply be changed to 254.

If the window ID doesn't exist, it returns 0.
*/

WinSet_Click_Through(I, T="254") {
	IfWinExist, % "ahk_id " I
	{
		If (T == "Off")
		{
			WinSet, AlwaysOnTop, Off, % "ahk_id " I
			WinSet, Transparent, Off, % "ahk_id " I
			WinSet, ExStyle, -0x20, % "ahk_id " I
		}
		Else
		{
			WinSet, AlwaysOnTop, On, % "ahk_id " I
			If(T < 0 || T > 254 || T == "On")
				T := 254
			WinSet, Transparent, % T, % "ahk_id " I
			WinSet, ExStyle, +0x20, % "ahk_id " I
		}
	}
	Else
		Return 0
}

An example:

Gui, 1: +LastFound
ID := WinExist()
Gui, 1: Add, Text, w300 +Center vExample, Clickable
Gui, 1: Show,, Example

Sleep (2000)

WinSet_Click_Through(ID)
GuiControl,, Example, Un-Clickable 

Sleep (2000)

WinSet_Click_Through(ID, 100)
GuiControl,, Example, Transparent

Sleep (2000)

WinSet_Click_Through(ID, "Off")
GuiControl,, Example, Clickable

Sleep (2000)

WinSet_Click_Through(ID, "On")
GuiControl,, Example, Un-Clickable

Sleep (2000)

ExitApp