Blank All of Your Screens with an AutoHotKey Script

If you work with computer aided presentations on Windows, then you probably know PowerPoint has options to show blank screens. Pressing “B” will give you a black screen and “W” will give you a white screen. These are useful options when you want to focus people’s attention on what you’re saying and away from any slides you might have up. For example if you need to discuss a point for which you don’t have a slide or if you want to tease something.

But have you ever considered situations where you are doing something other than a presentation application aided presentation? For example an application demonstration, working though a document, etc. Wouldn’t it be great if you could blank your screen on these occasions too? Or maybe you want to blank the screen with a different colour. Well that’s what I wanted to be able to do so I put together something to do it.

Whilst you could switch to a basic PowerPoint presentation and blank the screen each time or minimise to a very plain desktop I felt these were cumbersome or inconvenient to simply having something that could blank the screen for me any time I like. I also liked the idea of being able to choose a colour to blank to.

The solution I created is an AutoHotKey script that creates a top-most chromeless window of the desired colour that appears across all monitors. When the script is run and you press CTRL+WIN+B, the script will create the window and pressing ESC will close the window.

By default the script will produce a black screen, but if you want to assign an alternate colour press SHIFT+CTRL+WIN+B and a pop-up menu will appear. The menu allows you to select from a range of pre-defined colours.

If you want a different colour simply select Custom and a standard Windows colour picker dialog window will be displayed. Once a colour has been selected, pressing CTRL+WIN+B will then blank the screens to that colour.

As a pre-requisite of the colour selection option it uses a colour picker script available on the AutoHotKey forum. This should be saved as Lib-Colours.ahk in the same directory as the main script. A copy of the script has been included below in case the script should become unavailable or become incompatible in a later revision - full credit remains with rbrtryn on the AutoHotKey forum.

You can of course amend the script to include your own range of colours, default to a colour other than black and use your own hot key combinations.

Main Script (App-Blank Screen.ahk)

;Blank all monitors
;Copyright Stephen Millard - thoughtasylum.com
;For more information see http://www.thoughtasylum.com/blog/2014/7/30/blank-all-of-your-screens-with-an-autohotkey-script.html
;Press CTRL+WIN+b to blank screen
;Press SHIFT+CTRL+WIN+b to set screen blanking colour

#Include Lib-Colours.ahk


;Set global colour variable and default to black
InitBlankScreen()
{
    global strBlankColour, strBlankColourValue
    if strBlankColour = 
        strBlankColour = Black
    if strBlankColourValue = 
        strBlankColourValue = Black
}


;Blank all screens
;Ctrl+Win+b
^#b::
;Initialise
InitBlankScreen()
global strBlankColourValue

;Set a new window to have a background colour and remove its chrome
Gui, Color, %strBlankColourValue%
Gui, +ToolWindow -Caption +AlwaysOnTop

;The virtual screen is the bounding rectangle of all display monitors.
;We need an x & y origin and the height & width to create our overlay.
SysGet, intOriginX, 76
SysGet, intOriginY, 77
SysGet, intWidth, 78
SysGet, intHeight, 79

;Display the overlay until user presses ESC key
Gui, show, x%intOriginX% y%intOriginY% w%intWidth% h%intHeight%, NA
return


; Create a pop-up menu.
BuildBlankScreenColourMenu()
{
    ;Initialise
    InitBlankScreen()
    global strBlankColour
    
    Menu, menuBlankScreen, Add
    Menu, menuBlankScreen, DeleteAll
    
    ;Add a header to the menu
    Menu, menuBlankScreen, Add, Select Blank Screen Colour, MenuHandler
    Menu, menuBlankScreen, Disable, Select Blank Screen Colour
    Menu, menuBlankScreen, Add
    
    ;Add colours to the menu
    Menu, menuBlankScreen, Add, Black, MenuHandler
    Menu, menuBlankScreen, Add, Red, MenuHandler
    Menu, menuBlankScreen, Add, Blue, MenuHandler
    Menu, menuBlankScreen, Add, Green, MenuHandler
    Menu, menuBlankScreen, Add, Orange, MenuHandler
    Menu, menuBlankScreen, Add, Yellow, MenuHandler
    Menu, menuBlankScreen, Add, Purple, MenuHandler
    Menu, menuBlankScreen, Add, Silver, MenuHandler
    Menu, menuBlankScreen, Add, White, MenuHandler
    Menu, menuBlankScreen, Add, Custom, MenuHandler
    
    ;Set a check mark against the colour to be used
    Menu, menuBlankScreen, Check, %strBlankColour%
    
    return
}


;Process the menu selection
MenuHandler:
;Initialise
InitBlankScreen()
global strBlankColour, strBlankColourValue

;Uncheck the current blanking colour in the menu
;Menu, menuBlankScreen, Uncheck, %strBlankColour%

;Set the colour as the selected menu item
strBlankColour = %A_ThisMenuItem%
strBlankColourValue = %A_ThisMenuItem%

;Override for any non-standard colours
IfEqual, strBlankColour, Orange
{
    strBlankColourValue = FF6600
}

;For a custom colour use a standard OS colour picker
IfEqual, strBlankColour, Custom
{
    SetFormat IntegerFast, H

    Colours := [0x00FF00, 0xFF0000, 0xFF00FF]
    SelectedColour := ChooseColor(0x80FF, GuiHwnd, , , Colours*)
    
    IfEqual, ErrorLevel, 0x0
    {
        StringTrimLeft, SelectedColour, SelectedColour, 2
        strBlankColourValue = %SelectedColour%
    }
    Else
    {
        ;Default to black because it was cancelled
        strBlankColour = Black
        strBlankColourValue = Black
    }
   
}

return


;Display pop-up menu
;Shift+Ctrl+Win+b
+^#b::
BuildBlankScreenColourMenu()
Menu, menuBlankScreen, Show 
return

Colour Picker Script (Lib-Colours.ahk)

; SOURCE = http://www.autohotkey.com/board/topic/91229-windows-color-picker-plus/

/*!
    Function: ChooseColor([pRGB, hOwner, DlgX, DlgY, Palette])
        Displays a standard Windows dialog for choosing colors.

    Parameters:
        pRGB - The initial color to display in the dialog in RGB format.
               The default setting is Black.
        hOwner - The Window ID of the dialog's owner, if it has one. Defaults to
                0, i.e. no owner. If specified DlgX and DlgY are ignored.
        DlgX, DlgY - The X and Y coordinates of the upper left corner of the 
                     dialog. Both default to 0.
        Palette - An array of up to 16 RGB color values. These become the 
                  initial custom colors in the dialog.

    Remarks:
        The custom colors in the dialog are remembered between calls.
        
        If the user selects OK, the Palette array (if it exists) will be loaded 
        with the custom colors from the dialog. 

    Returns:
        If the user selects OK, the selected color is returned in RGB format 
        and ErrorLevel is set to 0. Otherwise, the original pRGB value is 
        returned and ErrorLevel is set to 1.
*/
ChooseColor(pRGB := 0, hOwner := 0, DlgX := 0, DlgY := 0, Palette*)
{
    static CustColors    ; Custom colors are remembered between calls
    static SizeOfCustColors := VarSetCapacity(CustColors, 64, 0)
    static StructSize := VarSetCapacity(ChooseColor, 9 * A_PtrSize, 0)
    
    CustData := (DlgX << 16) | DlgY    ; Store X in high word, Y in the low word

;___Load user's custom colors
    for Index, Value in Palette
        NumPut(BGR2RGB(Value), CustColors, (Index - 1) * 4, "UInt")

;___Set up a ChooseColor structure as described in the MSDN
    NumPut(StructSize, ChooseColor, 0, "UInt")
    NumPut(hOwner, ChooseColor, A_PtrSize, "UPtr")
    NumPut(BGR2RGB(pRGB), ChooseColor, 3 * A_PtrSize, "UInt")
    NumPut(&CustColors, ChooseColor, 4 * A_PtrSize, "UPtr")
    NumPut(0x113, ChooseColor, 5 * A_PtrSize, "UInt")
    NumPut(CustData, ChooseColor, 6 * A_PtrSize, "UInt")
    NumPut(RegisterCallback("ColorWindowProc"), ChooseColor, 7 * A_PtrSize, "UPtr")

;___Call the function
    ErrorLevel := ! DllCall("comdlg32\ChooseColor", "UPtr", &ChooseColor, "UInt")

;___Save the changes made to the custom colors
    if not ErrorLevel
        Loop 16
            Palette[A_Index] := BGR2RGB(NumGet(CustColors, (A_Index - 1) * 4, "UInt"))
        
    return BGR2RGB(NumGet(ChooseColor, 3 * A_PtrSize, "UINT"))
}

/*!
    Function: ColorWindowProc(hwnd, msg, wParam, lParam)
        Callback function used to modify the Color dialog before it is displayed

    Parameters:
        hwnd - Handle to the Color dialog window.
        msg - The message sent to the window.
        wParam - The handle to the control that has the keyboard focus.
        lParam - A pointer to the ChooseColor structure associated with the 
                 Color dialog.

    Remarks:
        This is intended to be a private function, called only by ChooseColor. 
        In response to a WM_INITDIALOG message, this function can be used to 
        modify the Color dialog before it is displayed. Currently it just moves 
        the window to a new X, Y location.

    Returns:
        If the hook procedure returns zero, the default dialog box procedure 
        also processes the message. Otherwise, the default dialog box procedure 
        ignores the message.
*/
ColorWindowProc(hwnd, msg, wParam, lParam)
{
    static WM_INITDIALOG := 0x0110
    
    if (msg <> WM_INITDIALOG)
        return 0
    
    hOwner := NumGet(lParam+0, A_PtrSize, "UPtr")
    if (hOwner)
        return 0

    DetectSetting := A_DetectHiddenWindows
    DetectHiddenWindows On
    CustData := NumGet(lParam+0, 6 * A_PtrSize, "UInt")
    DlgX := CustData >> 16, DlgY := CustData & 0xFFFF
    WinMove ahk_id %hwnd%, , %DlgX%, %DlgY%
    
    DetectHiddenWindows %DetectSetting%
    return 0
}

/*!
    Function: BGR2RGB(Color)
        Converts a BGR color value to a RGB one or vice versa.

    Parameters:
        Color - The BGR or RGB value to convert

    Returns:
        The converted value.
*/
BGR2RGB(Color)
{
    return  (Color & 0xFF000000) 
         | ((Color & 0xFF0000) >> 16) 
         |  (Color & 0x00FF00) 
         | ((Color & 0x0000FF) << 16)
}

If you found this useful please leave a comment and let people know how you are using it.

Author: Stephen Millard
Tags: | autohotkey | presentation |

Buy me a coffeeBuy me a coffee



Related posts that you may also like to read