Skip to content

Commit

Permalink
HideAndModifyTopmostWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluscream committed Apr 9, 2024
1 parent f098a40 commit 89421f6
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 20 deletions.
20 changes: 18 additions & 2 deletions lib/bluscream/ui/window.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ class Window {
this.text := text
}

fromTop() {
static
WinGet, hwnd, ID, A
return Window.fromId(hwnd)
}

fromId(id) {
static
idstr := "ahk_id " . id
Expand All @@ -36,6 +42,7 @@ class Window {
}

fromString(str) {
static
splt := StrSplit(str, " ahk_")
for i, part in split {
if (startsWith(part, "class"))
Expand Down Expand Up @@ -191,8 +198,17 @@ class Window {
restore() {
WinRestore, % this.str()
}
hide() {
WinHide, % this.str()
hide(force:=false) {
winStr := this.str()
WinHide, % winStr
if (force) {
WinSet, Style, -0x80000, % winStr ; Remove WS_VISIBLE style
WinSet, ExStyle, -0x80, % winStr ; Remove WS_EX_APPWINDOW style
WinSet, ExStyle, -0x20, % winStr ; Remove WS_EX_TOPMOST style
WinSet, Transparent, 255, % winStr ; Set transparency level (0-255)
WinSet, ExStyle, +0x00000020, % winStr ; Add WS_EX_TRANSPARENT style ; Make the window click-through
this.alwaysOnTop(false)
}
}
show() {
WinShow, % this.str()
Expand Down
30 changes: 15 additions & 15 deletions scripts/adb media keys.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; #include <consoleapps> ; https://github.com/Bluscream/ahk-scripts/blob/master/lib/consoleapps.ahk
#include <consoleapps> ; https://github.com/Bluscream/ahk-scripts/blob/master/lib/consoleapps.ahk

; Define the ADB path. Adjust the path according to your ADB installation.
adb_path := "adb"
Expand All @@ -20,13 +20,13 @@ MakeAdbCommand(command) {
global adb_path
return adb_path . " shell cmd media_session dispatch " . command
}
SendADBCommand(command) {
cmd := MakeAdbCommand(command)
RunWait % cmd, , Min UseErrorLevel
if (ErrorLevel = "ERROR") {
MsgBox, % "ADB command failed with exitcode " . ExitCode
}
}
; SendADBCommand(command) {
; cmd := MakeAdbCommand(command)
; RunWait % cmd, , Min UseErrorLevel
; if (ErrorLevel = "ERROR") {
; MsgBox, % "ADB command failed with exitcode " . ExitCode
; }
; }
; SendADBCommand(command) {
; cmd := MakeAdbCommand(command)
; ComOBJ := ComObjCreate("WScript.Shell").Exec(cmd)
Expand All @@ -35,13 +35,13 @@ SendADBCommand(command) {
; MsgBox, % "ADB command failed: " . Response
; }
; }
; SendADBCommand(command) { ; Requires http://www.autohotkey.com/board/topic/96903-simplified-versions-of-seans-stdouttovar/?p=610306
; cmd := MakeAdbCommand(command)
; result := StdOutToVar(MakeAdbCommand(cmd))
; if (InStr(result, "err") || InStr(result, "fail")) {
; MsgBox, % "ADB command failed:`n`n" . result
; }
; }
SendADBCommand(command) { ; Requires http://www.autohotkey.com/board/topic/96903-simplified-versions-of-seans-stdouttovar/?p=610306
cmd := MakeAdbCommand(command)
result := StdOutToVar(cmd)
if (InStr(result, "err") || InStr(result, "fail")) {
MsgBox, % "ADB command failed:`n`n" . result
}
}

; Hotkeys for media keys
#InstallKeybdHook
Expand Down
23 changes: 23 additions & 0 deletions scripts/force_hide_window.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; Function to hide, make transparent, and make click-through the current topmost window
HideAndModifyTopmostWindow() {
; Get the handle of the topmost window
WinGet, hwnd, ID, A

; Attempt to hide the window using different methods
WinHide, ahk_id %hwnd%
WinSet, Style, -0x80000, ahk_id %hwnd% ; Remove WS_VISIBLE style
WinSet, ExStyle, -0x80, ahk_id %hwnd% ; Remove WS_EX_APPWINDOW style
WinSet, ExStyle, -0x20, ahk_id %hwnd% ; Remove WS_EX_TOPMOST style

; Make the window transparent
WinSet, Transparent, 200, ahk_id %hwnd% ; Set transparency level (0-255)

; Make the window click-through
WinSet, ExStyle, +0x00000020, ahk_id %hwnd% ; Add WS_EX_TRANSPARENT style

; Optionally, set the window to be always on top to ensure it remains hidden
WinSet, AlwaysOnTop, Off, ahk_id %hwnd%
}

; Hotkey to trigger the function
^SPACE::HideAndModifyTopmostWindow()
3 changes: 2 additions & 1 deletion scripts/hotkeys.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Persistent
#Persistent
#NoTrayIcon
#NoEnv
#SingleInstance, force
Expand Down Expand Up @@ -55,6 +55,7 @@ showHotKeys() {
; < = This prefix character causes the hotkey to be triggered by the left-hand version of the key only. This is usually only necessary for keys whose right-hand version might have a different effect such as the NumPad keys. This prefix character is equivalent to specifying {LAlt} for this hotkey.

<#h::showHotKeys() ; Win + H
+#h::Window.fromTop().hide(true) ; Shift + Win + H ; Force hide current window
<#c::Run cmd ; Win + C
+#c::ShellRun("cmd") ; Shift + Win + C
<#p::Run powershell ; Win + P
Expand Down
3 changes: 1 addition & 2 deletions scripts/winclose.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ titles.push({title:"Arma 2: British Armed Forces Uninstall ahk_class #32770",tex
titles.push({title:"Arma 2 Army of The Czech Republic Setup ahk_class #32770 ahk_exe datacachepreprocessor.exe",text:"!!! MISSING STRING",action:"CloseWindow"})
titles.push({title:"Steam Error ahk_class #32770 ahk_exe datacachepreprocessor.exe",text:"Application load error ",action:"CloseWindow"})
titles.push({title:"vorpX Control ahk_class #32770 ahk_exe vorpControl.exe",text:"The vorpX Service is not running. vorpX will try to start it now.",action:"CloseWindow"})

; titles.push({title:"RivaTunerStatisticsServer ahk_class #32770 ahk_exe RTSS.exe",text:"Direct3D12 components cannot be hooked right now. It is strongly recommended to restart application.",action:"CloseWindow"})
titles.push({title:"RivaTunerStatisticsServer ahk_class #32770 ahk_exe RTSS.exe",text:"Direct3D12 components cannot be hooked right now. It is strongly recommended to restart application.",action:"CloseWindow"})

; titles.push({title: "DB Browser for SQLite ahk_class Qt5QWindowIcon ahk_exe DB Browser for SQLite.exe", text: "", action: "Click:X232 Y67"})
; titles.push({title: "ahk_class CabinetWClass ahk_exe Explorer.EXE", text: "UNREGISTERED VERSION", action: "CloseWindow"})
Expand Down

0 comments on commit 89421f6

Please sign in to comment.