Skip to content

Instantly share code, notes, and snippets.

@ovcharik
Last active September 3, 2021 09:59
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ovcharik/397e02e1bcfe4d4473ae2cbdde09a7aa to your computer and use it in GitHub Desktop.
Save ovcharik/397e02e1bcfe4d4473ae2cbdde09a7aa to your computer and use it in GitHub Desktop.
Autohotkey script. Run/Show/Hide Windows Terminal on top of the screen by F1 hotkey.
#NoEnv
#SingleInstance force
SetWinDelay, -1
DetectHiddenWindows, on
Menu, Tray, NoStandard
; Menu, Tray, Icon, wt-tilda.ico
Menu, Tray, Add, Exit, Exit
last_active_id := ""
shell_class := "ahk_class Shell_TrayWnd"
wt_class := "ahk_class CASCADIA_HOSTING_WINDOW_CLASS"
wt_exe := "wt.exe"
wt_id := ""
; hide/show on F1
F1::
Volume_Mute::
If WinExist(wt_class) {
WinGet, wt_id, ID, %wt_class%
toggle()
} else {
init()
}
return
Exit:
ExitApp
; methods
showConsole() {
global
WinMove, ahk_id %wt_id%,, 0, 0, A_ScreenWidth,
WinActivate ahk_id %wt_id%
WinShow ahk_id %wt_id%
}
toggle() {
global
If WinActive("ahk_id " . wt_id) {
; last active window is console
If (wt_id = last_active_id) {
WinGet, last_active_id, ID, %shell_class%
}
WinActivate ahk_id %last_active_id%
WinHide ahk_id %wt_id%
} else {
; update last active window
WinGet, last_active_id, ID, A
showConsole()
}
}
init() {
global
WinGet, last_active_id, ID, A
Run %wt_exe%
WinWait %wt_class%
WinGet, wt_id, ID, %wt_class%
WinHide ahk_id %wt_id%
WinSet, Style, -0x00C00000, ahk_id %wt_id% ; WS_CAPTION - no border and title
WinSet, Style, -0x00040000, ahk_id %wt_id% ; WS_SIZEBOX - no resize
WinSet, ExStyle, +0x00000080, ahk_id %wt_id% ; WS_EX_TOOLWINDOW
WinSet, ExStyle, +0x00000100, ahk_id %wt_id% ; WS_EX_OVERLAPPEDWINDOW
showConsole()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment