Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Adjust the variables below. You'll usually want to start with 0 and adjust up bit by bit until all borders/scrollbars/etc are hidden.
- ;;;;;;;;;;;;;;;;;;;;;;;;;;
- global BGColor := "000000" ; The background color (default is black)
- global TopSub := 26 ; How many pixels you want to mask from the top of the application window
- global BottomSub := 3 ; How many pixels you want to mask from the bottom of the application window
- global LeftSub := 0 ; How many pixels you want to mask from the left of the application window
- global RightSub := 0 ; How many pixels you want to mask from the right of the application window
- ;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Code begins below
- ;;;;;;;;;;;;;;;;;;;;;;;;;;
- global WindowID, WinPosX, WinPosY, WindowWidth, WindowHeight
- global WindowState := 0
- global funcLock := 0
- global unloadRequest := 0
- Loop {
- If WinExist("ahk_id " . WindowID) {
- If WinActive("ahk_id " . WindowID) {
- If (WindowState = 0) {
- StartMask()
- }
- } Else {
- If (WindowState = 1) {
- StopMask()
- }
- }
- } Else {
- If (WindowState = 1) {
- StopMask()
- }
- }
- Sleep, 10
- }
- F12::
- funcLock := 1
- If WinExist("ahk_id " . WindowID) {
- } Else {
- WinGet, TempWindowID, ID, A
- WindowID:=TempWindowID
- }
- If WinExist("ahk_id " . WindowID) {
- If (WindowState = 0) {
- StartMask()
- } Else {
- StopMask()
- ; In this case we're pushing F12 for a second time, so clear the remembered WindowID so it stops auto-applying when the window has focus:
- WindowID:=""
- }
- }
- funcLock := 0
- return
- StartMask() {
- Gui, Color, %BGColor%
- Gui -Caption -ToolWindow +AlwaysOnTop
- WinGetPos, WinPosX, WinPosY, WindowWidth, WindowHeight, ahk_id %WindowID%
- ; Hide Windows Task Bar and Start Button. (Remove the following two lines if you don't want that behaviour)
- ; WinHide ahk_class Shell_TrayWnd
- ; WinHide Start ahk_class Button
- ; Get the x/y coords of the upper-left position of the window in order to center it on the screen, and then move it there
- WindowXCoord:=((A_ScreenWidth - WindowWidth)/2)
- WindowYCoord:=((A_ScreenHeight - WindowHeight)/2)
- WinMove, ahk_id %WindowID%, , WindowXCoord, WindowYCoord
- ; Build the region string that will define the full monitor area (this is what will be masked by the gui window)
- FullScreenRegion:="0-0 " ; UPPER_LEFT
- FullScreenRegion:=FullScreenRegion . A_ScreenWidth . "-0 " ; UPPER_RIGHT
- FullScreenRegion:=FullScreenRegion . A_ScreenWidth . "-" . A_ScreenHeight . " " ; LOWER_RIGHT
- FullScreenRegion:=FullScreenRegion . "0-" . A_ScreenHeight . " " ; LOWER_LEFT
- FullScreenRegion:=FullScreenRegion . "0-0 " ; UPPER_LEFT (again)
- ; Build the region string that will define the application area (this is the window within the full area that will NOT be masked by the gui window). Take into account the adjustments we defined to take into account window borders/scrollbars/menus/etc
- GameScreenRegion:=WindowXCoord+LeftSub . "-" . WindowYCoord+TopSub . " " ; UPPER_LEFT
- GameScreenRegion:=GameScreenRegion . WindowXCoord+WindowWidth-RightSub . "-" . WindowYCoord+TopSub . " " ; UPPER_RIGHT
- GameScreenRegion:=GameScreenRegion . WindowXCoord+WindowWidth-RightSub . "-" . WindowYCoord+WindowHeight-BottomSub . " " ; LOWER_RIGHT
- GameScreenRegion:=GameScreenRegion . WindowXCoord+LeftSub . "-" . WindowYCoord+WindowHeight-BottomSub . " " ; LOWER_LEFT
- GameScreenRegion:=GameScreenRegion . WindowXCoord+LeftSub . "-" . WindowYCoord+TopSub ; UPPER_LEFT (again)
- ; Show the masking gui (and center it)
- Gui, Show, W1920 H1080, BlackScreen
- WinMove, BlackScreen, , 0, 0
- ; Define the masking regions we set up above, with the transparent region in the middle
- WinSet, Region, % FullScreenRegion . GameScreenRegion, BlackScreen
- ; Now bring the application window to the forefront
- WinActivate, ahk_id %WindowID%
- WindowState:=!WindowState
- return
- }
- StopMask() {
- ; Move the application back to where it originally was:
- WinMove, ahk_id %WindowID%, , WinPosX, WinPosY, WindowWidth, WindowHeight
- ; Show the task bar again
- ; WinShow ahk_class Shell_TrayWnd
- ; WinShow Start ahk_class Button
- ; Remove the masking gui:
- Gui, destroy
- ;WinSet, Region,, ahk_id %WindowID% ; Restore the window to its original/default display area.
- WindowState:=!WindowState
- return
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement