HotkeyPlus is a modern, full-featured custom Hotkey control for AutoHotkey v2.
It is designed as a drop-in replacement for the standard Win32 msctls_hotkey32 control (MyGui.Add("Hotkey")), completely overcoming its legacy limitations such as the inability to register Escape, Pause, PrintScreen, Tab, Enter, Space, Backspace, Delete, AppsKey, Windows Key (#) combinations, and mouse buttons.
The default Windows Common Control used by AutoHotkey (msctls_hotkey32) is over 25 years old and restricts many of the most useful keys from being assigned as hotkeys. HotkeyPlus completely solves these issues:
| Feature / Key | Standard Hotkey (msctls_hotkey32) |
HotkeyPlus |
|---|---|---|
Escape |
❌ Closes dialog / ignored | Captured as a hotkey |
Pause / Break |
❌ Ignored | Fully supported |
PrintScreen |
❌ Ignored / intercepted by OS | Captured seamlessly |
Tab |
❌ Navigates focus away | Captured as a hotkey (e.g. Shift + Tab) |
Enter / NumpadEnter |
❌ Triggers default button | Captured as a hotkey (e.g. Ctrl + Enter) |
Space |
❌ Triggers buttons / ignored | Captured as a hotkey (e.g. Alt + Space) |
Backspace |
❌ Clears the box | Captured as a hotkey |
Delete |
❌ Clears the box | Captured as a hotkey |
AppsKey |
❌ Not supported | Captured as a hotkey |
Windows Key (#) |
❌ Not supported | Full support (e.g. Win + Z, Win + Shift + Esc) |
| Mouse Buttons | ❌ Not supported | MButton, XButton1, XButton2, WheelUp, WheelDown |
| Live Modifier Preview | ❌ No | Shows [ Ctrl + Alt + ... ] while keys are held |
| Dedicated Clear Button | ❌ No (requires Backspace) | Built-in [✕] button and right-click context menu |
| AHK v2 Native Syntax | Yes | MyGui.AddHotkeyPlus(...) |
- Total Key Freedom: Assign any key on the keyboard, including navigation keys (
Home,End,Page Up,Page Down, Arrows),F1–F24, Media keys, and Numpad keys. - Windows Key Combos: Fully captures combinations with the Windows key (e.g.,
#z,#!Escape) without triggering Windows Shell shortcuts while recording. - Smart Input Capture: Combines Win32 window subclassing (
DLGC_WANTALLKEYS) with focus-scopedInputHookto intercept keystrokes before dialog managers or the OS consume them. - Live Visual Feedback: While holding down modifier keys (
Ctrl,Alt,Shift,Win), the control displays a live preview (e.g.[ Ctrl + Shift + ... ]). - Dual Format Output & Numpad Formatting:
hk.Value: Machine-ready AHK syntax (^!Escape,#+Pause,PrintScreen,!Enter,Numpad5).hk.Text: Human-friendly presentation (Ctrl + Alt + Escape,Win + Shift + Pause,Numpad 5).
- Leak-Free & Safe Lifecycle: Subclassing and callbacks are automatically and safely detached on window destruction (
WM_NCDESTROY) or GUI closure, completely preventing memory/handle leaks even when dynamically callingMyGui.Destroy(). - Intelligent Focus Management: Shifts focus away safely upon key assignment (to the clear button or parent GUI) to prevent accidental keystroke overrides.
- Clean Reset & Context Menu: Right-click on the control to access a context menu with "Clear Hotkey" and "Reset to Default" options.
- AutoHotkey v2.0 or higher (64-bit or 32-bit)
- Windows 10 / 11
Simply download or copy hotkeyplus.ahk into your project folder or standard AHK library directory, and include it in your script:
#Requires AutoHotkey v2.0 #Include "hotkeyplus.ahk"
#Requires AutoHotkey v2.0 #Include "hotkeyplus.ahk" MyGui := Gui(, "HotkeyPlus Example") ; Add the HotkeyPlus control to your GUI hk := MyGui.AddHotkeyPlus("w240 vMyShortcut", "^!Escape") ; Listen for changes hk.OnEvent("Change", (ctrl, newVal) => ( ToolTip("Hotkey updated: " . newVal . "`nDisplay: " . ctrl.Text) )) MyGui.Show()
You can create a HotkeyPlus control either via the prototype extension or direct class instantiation:
; Method 1: Gui prototype extension (Recommended) hk := MyGui.AddHotkeyPlus(Options?, DefaultValue?) ; Method 2: Direct constructor hk := HotkeyPlus(MyGui, Options?, DefaultValue?)
| Option | Description | Example |
|---|---|---|
wN |
Width of the control in pixels (default: 180). |
w220 |
hN |
Height of the control in pixels (default: 24). |
h28 |
xN / yN |
Standard AHK coordinate positioning. | x20 y50, yp hp |
vName |
Associated variable name. | vSelectedKey |
NoClear |
Disables and hides the companion [✕] clear button. |
w200 NoClear |
NoWin |
Disallows Windows key (#) combinations. |
w200 NoWin |
NoMouse |
Disallows mouse buttons from being captured. | w200 NoMouse |
| Property | Type | Access | Description |
|---|---|---|---|
Value |
String |
Read / Write | AHK hotkey representation (e.g. ^!Escape, #+Pause, F12). Setting this value triggers the Change event. |
Text |
String |
Read-only | Human-readable string (e.g. Ctrl + Alt + Escape, Win + Shift + Pause). Returns "None" if empty. |
Placeholder |
String |
Read / Write | Text displayed when control is listening for a key (default: "Press a key..."). |
Hwnd |
Integer |
Read-only | HWND handle of the underlying Edit control. |
EditCtrl |
Gui.Control |
Read-only | The underlying Gui.Control object for the Edit field. |
ClearBtn |
Gui.Control |
Read-only | The underlying Gui.Control object for the clear button (or "" if NoClear). |
Enabled |
Boolean |
Read / Write | Enables or disables both the input box and clear button. |
Visible |
Boolean |
Read / Write | Shows or hides the control. |
Focused |
Boolean |
Read-only | true if the control currently has keyboard focus. |
Gui |
Gui |
Read-only | Reference to the parent Gui object. |
Name |
String |
Read-only | Variable name specified via vName. |
AllowWin |
Boolean |
Read / Write | Allows or restricts Windows key combinations. |
AllowMouse |
Boolean |
Read / Write | Allows or restricts mouse button inputs. |
Focuses the control and activates listening mode.
Clears the current hotkey value (Value := "") and displays empty.
Restores the hotkey to the initial defaultValue specified during creation.
Registers an event listener. Supported events:
"Change": Triggered when a new hotkey is confirmed or cleared. Passes(ctrl, newValue)to the callback."Focus": Triggered when listening mode starts."LoseFocus": Triggered when listening mode ends.
hk.OnEvent("Change", (ctrl, val) => MsgBox("Selected: " . val))
The repository includes an interactive demo showcasing standard Hotkey limitations alongside HotkeyPlus:
# Run with AutoHotkey v2
AutoHotkey64.exe demo.ahkThe demo includes:
- Side-by-side comparison between the standard
Hotkeycontrol andHotkeyPlus. - Quick test preset buttons (
Escape,Pause,PrintScreen,Shift+Tab,Win + Z,Ctrl+Enter,Alt+Space,Backspace). - A live hotkey binder that dynamically registers the hotkey to the operating system using AHK's
Hotkey()function.
-
Win32 Subclassing (
SetWindowSubclass):- Responds to
WM_GETDLGCODEwithDLGC_WANTALLKEYS (0x0004), preventing the Windows Dialog Manager from consumingEscape,Tab, andEnter. - Intercepts
WM_CHARandWM_SYSCHARto suppress default character typing and Windows beep sounds. - Monitors mouse messages (
WM_MBUTTONDOWN,WM_XBUTTONDOWN,WM_MOUSEWHEEL) when focused. - Automatically unhooks subclassing and frees callbacks upon receiving
WM_NCDESTROY (0x0082)or GUI closure, guaranteeing zero memory or handle leaks regardless of how the parent window is closed.
- Responds to
-
Scoped
InputHookCapture:- Starts only when the control receives focus (
WM_SETFOCUS) and stops immediately upon receiving a key combination or losing focus (WM_KILLFOCUS). - Uses
+Ssuppression to prevent intercepted shortcut keys (likeWin+E,Alt+F4, orEscape) from triggering system actions while the user is assigning them.
- Starts only when the control receives focus (
-
Smart Focus Shift:
- Once a valid hotkey is detected and assigned, the control immediately shifts focus to the companion Clear button or the parent GUI window. This prevents subsequent typing from unintentionally overwriting the newly selected hotkey.
- First release
See the LICENSE file for license details.
Contributions are welcome! If you'd like to add features, fix bugs, or improve the code, feel free to open a pull request.
Author: Mesut Akcan
Email: [email protected]
Blog: mesutakcan.blogspot.com
GitHub: mesutakcan
YouTube: Mesut Akcan