; Autohotkey Keyboard Help GUI

; v1.1 by IBNobody

; 1. Go to KLE (http://www.keyboard-layout-editor.com/) create your keymap.

; 2. Download the keymap as a PNG.

; 3. Add/remove/replace lines in cLayerPicture with paths to your pictures.

; Each picture represents a layer. Try to keep the pictures the same size.

; 4. Edit the script

; 5. Edit cLayerName to match the names of the layers.

; 6. Run this script.

; Pressing any key or clicking on the window will cause the help window to close.

; Pressing a new hotkey defined as a different layout will change the displayed layout.

; Pressing up/down/left/right/=/-/+ will change the displayed layout

; Use QMK/TMK and want a quick way to edit your Keyboard Layouts?

; https://docs.google.com/spreadsheets/d/1jSnt4iHeVmF_P8mvwC7ke3bwFeODJz2woejqeDRZtWI/edit?usp=sharing

;{ --- Defines ----------------------------------------------------------------

#NoEnv

#MaxHotkeysPerInterval 99000000

#HotkeyInterval 99000000

;~ #KeyHistory 0

;~ ListLines Off

Process , Priority , , H ;if unstable, comment or remove this line

SetBatchLines , - 1

SetKeyDelay , - 1 , - 1

SetMouseDelay , - 1

SetDefaultMouseSpeed , 0

SetWinDelay , - 1

SetControlDelay , - 1

SendMode Input

#InstallMouseHook

#InstallKeybdHook

#SingleInstance Force

#WinActivateForce

#MaxThreadsPerHotkey 1

DetectHiddenWindows On

SetTitleMatchMode 2

SetWorkingDir %A_ScriptDir%

CoordMode , Pixel , Screen ; Pixel Searching

;}

;{ --- Constants & Variables --------------------------------------------------

; Constants

; Use Keyboard Layout Editor to "download" a PNG image of the keymap

; The examples below expect the PNG image to be in the same folder as the script.

cLayerPicture := [ ".\atomic_qwerty.png"

, ".\atomic_upper.png"

, ".\atomic_lower.png" ]

cLayerName := [ "ATOMIC - QWERTY"

, "ATOMIC - UPPER LAYER"

, "ATOMIC - LOWER LAYER" ]

; Set this to true to have the GUI cycle from the first to last layer and vice versa when

; the arrow keys are pressed. Otherwise, the GUI will stop at the first or last layer.

cLoopOnCycle := true

; Variables

vPicHandle1 := 0

vPicHandle2 := 0

vvHotkeyHandle := ""

vActivePicControl := 1

vCurrentKeyboardLayer := 0

;}

;{ --- Keybinds ---------------------------------------------------------------

; Change these to use whatever hotkey you want to use

F1 :: ExitApp

F2 ::KeyboardHelpGui ( 1 )

F3 ::KeyboardHelpGui ( 2 )

F4 ::KeyboardHelpGui ( 3 )

;}

; --- Functions --------------------------------------------------------------

;{ Function Description

; Display, Swap, or Close Keyboard Help GUI

KeyboardHelpGui ( vNewKeyboardLayer )

{

global vCurrentKeyboardLayer , cLayerPicture , cLayerName

vKeyboardPicture := cLayerPicture [ vNewKeyboardLayer ]

vKeyboardLayerName := cLayerName [ vNewKeyboardLayer ]

; If Keyboard Help GUI is already open...

if ( KeyboardHelpGuiExists ( ) )

{

; If a new picture is to be displayed, swap the picture. Otherwise, destroy the GUI.

if ( vCurrentKeyboardLayer ! = vNewKeyboardLayer )

{

vCurrentKeyboardLayer := vNewKeyboardLayer

KeyboardHelpGuiSwap ( vKeyboardPicture , vKeyboardLayerName )

}

else

{

KeyboardHelpGuiDestroy ( )

}

}

else

{

vCurrentKeyboardLayer := vNewKeyboardLayer

KeyboardHelpGuiCreate ( vKeyboardPicture , vKeyboardLayerName )

}

return

}

KeyboardHelpGuiCycle ( vDirection , vLoop )

{

global vCurrentKeyboardLayer , cLayerPicture

vNewKeyboardLayer := vCurrentKeyboardLayer + vDirection

if ( vLoop )

{

if ( vNewKeyboardLayer < 1 )

{

vNewKeyboardLayer := cLayerPicture . MaxIndex ( )

}

else if ( vNewKeyboardLayer > cLayerPicture . MaxIndex ( ) )

{

vNewKeyboardLayer := 1

}

}

else

{

if ( vNewKeyboardLayer < 1 )

{

vNewKeyboardLayer := 1

}

else if ( vNewKeyboardLayer > cLayerPicture . MaxIndex ( ) )

{

vNewKeyboardLayer := cLayerPicture . MaxIndex ( )

}

}

if ( vNewKeyboardLayer ! = vCurrentKeyboardLayer )

{

KeyboardHelpGui ( vNewKeyboardLayer )

}

return

}

; Check if Keyboard Help GUI is already open

KeyboardHelpGuiExists ( )

{

; If Keyboard Help GUI is already open...

Gui KeyboardHelp: + LastFoundExist

return WinExist ( )

}

; Keyboard Help GUI OnClick Callback

KeyboardHelpGuiHotkey ( )

{

global vHotkeyHandle , cLoopOnCycle

handle := vHotkeyHandle

GuiControl KeyboardHelp: , vHotkeyHandle , ""

GuiControl KeyboardHelp: Focus , vHotkeyHandle

if ( ( vHotkeyHandle == "Right" ) || ( vHotkeyHandle == "Up" ) || ( vHotkeyHandle == "=" ) || ( vHotkeyHandle == "Right" ) || ( vHotkeyHandle == "Up" ) || ( vHotkeyHandle == "NumpadAdd" ) )

{

KeyboardHelpGuiCycle ( 1 , cLoopOnCycle )

}

else if ( ( vHotkeyHandle == "Left" ) || ( vHotkeyHandle == "Down" ) || ( vHotkeyHandle == "-" ) || ( vHotkeyHandle == "Left" ) || ( vHotkeyHandle == "Down" ) || ( vHotkeyHandle == "NumpadSub" ) )

{

KeyboardHelpGuiCycle ( - 1 , cLoopOnCycle )

}

else

{

KeyboardHelpGuiDestroy ( )

}

return

}

; Keyboard Help GUI OnClick Callback

KeyboardHelpGuiClick ( )

{

GuiControl KeyboardHelp: Focus , vHotkeyHandle

KeyboardHelpGuiDestroy ( )

return

}

; Keyboard Help GUI OnClose Callback

KeyboardHelpGuiClose ( guiHwnd )

{

KeyboardHelpGuiDestroy ( )

return

}

; Keyboard Help GUI onEscape Callback

KeyboardHelpGuiEscape ( guiHwnd )

{

KeyboardHelpGuiDestroy ( )

return

}

; Create and show the Keyboard Help GUI

KeyboardHelpGuiCreate ( vKeyboardPicture , vTitle )

{

global vPicHandle1 , vPicHandle2 , vHotkeyHandle

global vActivePicControl := 1

; Create the GUI and set its parameters

Gui KeyboardHelp: new , , %vTitle%

Gui KeyboardHelp: + AlwaysOnTop - Resize - SysMenu

; Create a Hotkey control outside the bounds of the window to send any keypresses to a callback

Gui KeyboardHelp: Add , Hotkey , gKeyboardHelpGuiHotkey vvHotkeyHandle x - 20 y - 20

;~ Gui KeyboardHelp: Add, Hotkey, gKeyboardHelpGuiHotkey vvHotkeyHandle x0 y500

; Create two image controls (one hidden) and set them to send any mouse clicks to a callback

Gui KeyboardHelp: Add , Picture , gKeyboardHelpGuiClick vvPicHandle1 x10 y10 , %vKeyboardPicture%

Gui KeyboardHelp: Add , Picture , gKeyboardHelpGuiClick vvPicHandle2 x10 y10 , %vKeyboardPicture%

GuiControl KeyboardHelp: Focus , vHotkeyHandle

GuiControl KeyboardHelp: Hide , vPicHandle2

; Show the GUI

Gui KeyboardHelp: Show , AutoSize Center , %vTitle%

return

}

; Swap the picture on the Keyboard Help GUI

KeyboardHelpGuiSwap ( vNewKeyboardPicture , vTitle )

{

static

global vActivePicControl

; Update the hidden picture control with the new picture and display it

if ( vActivePicControl == 1 )

{

vActivePicControl := 2

GuiControl KeyboardHelp: , vPicHandle2 , %vNewKeyboardPicture%

GuiControl KeyboardHelp: show , vPicHandle2

GuiControl KeyboardHelp: hide , vPicHandle1

}

else

{

vActivePicControl := 1

GuiControl KeyboardHelp: , vPicHandle1 , %vNewKeyboardPicture%

GuiControl KeyboardHelp: show , vPicHandle1

GuiControl KeyboardHelp: hide , vPicHandle2

}

Gui KeyboardHelp: Show , AutoSize Center , %vTitle%

return

}

; Destroy the Keyboard Help GUI

KeyboardHelpGuiDestroy ( )

{

Gui KeyboardHelp: Destroy

return

}

;}

;{ ShellHook Callback

;~ ShellMessage( wParam, lParam )

;~ {

;~ WinGetTitle, Title, ahk_id %lParam%

;~ WinGetClass, ClassOfWin, ahk_id %lParam%

;~ ToolTip, w = %wParam% l = %lParam% Title = %Title% Class = %ClassOfWin%

;~ }