Skip to content

Instantly share code, notes, and snippets.

@nimaid
Last active April 19, 2024 22:26
Show Gist options
  • Save nimaid/1061c0231776bae32aa04abba8f33bb5 to your computer and use it in GitHub Desktop.
Save nimaid/1061c0231776bae32aa04abba8f33bb5 to your computer and use it in GitHub Desktop.
AutoHotKey (v1) scipt to add useful tools for blacking out the screen and hiding the cursor/border/taskbar
SystemCursor("Init")
GuiShown = false
DisplayHelpMsg()
#N:: ; Toggle blackout window = Win + N
WinGetTitle, title, A
If GuiShown = false
{
Gui, Color, black
Gui -Caption
Gui, Show, x0 y0 w%A_ScreenWidth% h%A_ScreenHeight%
GuiShown = true
}
Else
{
Gui Destroy
GuiShown = false
}
if WinExist(title)
WinActivate
return
#B:: ; Toggle border = Win + B
WindowBorder("Toggle")
return
#M:: ; Toggle mouse cursor = Win + M
SystemCursor("Toggle")
return
#V:: ; Toggle taskbar = Win + V
WinGetTitle, title, A
SystemTaskbar("Toggle")
WinActivate, title
return
#C:: ; Exit script = Win + C
Gui Destroy
WindowBorder("On")
SystemCursor("On")
SystemTaskbar("On")
MsgBox, 0, Blackout - Exit, Blackout is now closed.
ExitApp
return
#X:: ; Help dialog = Win + X
DisplayHelpMsg()
return
DisplayHelpMsg()
{
MsgBox, 0, Blackout - Hotkeys, Blackout behind active window:`n`tWin + N`nToggle active window border:`n`tWin + B`nToggle mouse cursor visible:`n`tWin + M`nToggle taskbar visible:`n`tWin + V`nDisplay this help box:`n`tWin + X`nExit script:`n`tWin + C
}
SystemTaskbar(OnOff="On") ; OFF = "Off"; TOGGLE = "Toggle", ON = others
{
if (OnOff = "Off")
{
WinHide, ahk_class Shell_TrayWnd
WinHide, ahk_class Shell_SecondaryTrayWnd
}
if (OnOff = "Toggle")
{
If WinExist("ahk_class Shell_TrayWnd")
{
WinHide, ahk_class Shell_TrayWnd
WinHide, ahk_class Shell_SecondaryTrayWnd
}
Else
{
WinShow, ahk_class Shell_TrayWnd
WinShow, ahk_class Shell_SecondaryTrayWnd
}
}
else
{
WinShow, ahk_class Shell_TrayWnd
WinShow, ahk_class Shell_SecondaryTrayWnd
}
}
WindowBorder(OnOff="Toggle") ; OFF = "Off"; TOGGLE = "Toggle", ON = others
{
if (OnOff = "Off")
{
WinSet, Style, -0xC40000, A
}
if (OnOff = "Toggle")
{
WinSet, Style, ^0xC40000, A
}
else
{
WinSet, Style, +0xC40000, A
}
}
SystemCursor(OnOff=1) ; INIT = "I","Init"; OFF = 0,"Off"; TOGGLE = -1,"T","Toggle"; ON = others
{
static AndMask, XorMask, $, h_cursor
,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 ; system cursors
, b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13 ; blank cursors
, h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13 ; handles of default cursors
if (OnOff = "Init" or OnOff = "I" or $ = "") ; init when requested or at first call
{
$ = h ; active default cursors
VarSetCapacity( h_cursor,4444, 1 )
VarSetCapacity( AndMask, 32*4, 0xFF )
VarSetCapacity( XorMask, 32*4, 0 )
system_cursors = 32512,32513,32514,32515,32516,32642,32643,32644,32645,32646,32648,32649,32650
StringSplit c, system_cursors, `,
Loop %c0%
{
h_cursor := DllCall( "LoadCursor", "uint",0, "uint",c%A_Index% )
h%A_Index% := DllCall( "CopyImage", "uint",h_cursor, "uint",2, "int",0, "int",0, "uint",0 )
b%A_Index% := DllCall("CreateCursor","uint",0, "int",0, "int",0
, "int",32, "int",32, "uint",&AndMask, "uint",&XorMask )
}
}
if (OnOff = 0 or OnOff = "Off" or $ = "h" and (OnOff < 0 or OnOff = "Toggle" or OnOff = "T"))
$ = b ; use blank cursors
else
$ = h ; use the saved cursors
Loop %c0%
{
h_cursor := DllCall( "CopyImage", "uint",%$%%A_Index%, "uint",2, "int",0, "int",0, "uint",0 )
DllCall( "SetSystemCursor", "uint",h_cursor, "uint",c%A_Index% )
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment