GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - mesutakcan/hotkeyplus-ahk: Enhanced Hotkey Control for AutoHotkey v2

BranchesTags
Open more actions menu

Latest commit

 

History

4 Commits
4 Commits

Folders and files

NameName
Last commit message
Last commit date
LICENSE
LICENSE
 
 
README.md
README.md
 
 
demo.ahk
demo.ahk
 
 
hotkeyplus.ahk
hotkeyplus.ahk
 
 

Repository files navigation

HotkeyPlus for AutoHotkey v2

AutoHotkey Platform License: MIT

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.


⚡ Why HotkeyPlus?

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(...)

🚀 Key Features

  • 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-scoped InputHook to 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 calling MyGui.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.

📋 Requirements

  • AutoHotkey v2.0 or higher (64-bit or 32-bit)
  • Windows 10 / 11

📦 Installation

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"

💡 Quick Start

#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()

📖 API Reference

Creation

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?)

Options String Parameters

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

Properties

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.

Methods

hk.Focus()

Focuses the control and activates listening mode.

hk.Clear()

Clears the current hotkey value (Value := "") and displays empty.

hk.Reset()

Restores the hotkey to the initial defaultValue specified during creation.

hk.OnEvent(EventName, Callback)

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))

🎮 Running the Demo

The repository includes an interactive demo showcasing standard Hotkey limitations alongside HotkeyPlus:

# Run with AutoHotkey v2
AutoHotkey64.exe demo.ahk

The demo includes:

  1. Side-by-side comparison between the standard Hotkey control and HotkeyPlus.
  2. Quick test preset buttons (Escape, Pause, PrintScreen, Shift+Tab, Win + Z, Ctrl+Enter, Alt+Space, Backspace).
  3. A live hotkey binder that dynamically registers the hotkey to the operating system using AHK's Hotkey() function.

🛠️ How It Works Under the Hood

  1. Win32 Subclassing (SetWindowSubclass):

    • Responds to WM_GETDLGCODE with DLGC_WANTALLKEYS (0x0004), preventing the Windows Dialog Manager from consuming Escape, Tab, and Enter.
    • Intercepts WM_CHAR and WM_SYSCHAR to 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.
  2. Scoped InputHook Capture:

    • Starts only when the control receives focus (WM_SETFOCUS) and stops immediately upon receiving a key combination or losing focus (WM_KILLFOCUS).
    • Uses +S suppression to prevent intercepted shortcut keys (like Win+E, Alt+F4, or Escape) from triggering system actions while the user is assigning them.
  3. 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.

History

v1.0.0 (2026-09-02)

  • First release

License

See the LICENSE file for license details.


Contributing

Contributions are welcome! If you'd like to add features, fix bugs, or improve the code, feel free to open a pull request.


Contact

Author: Mesut Akcan
Email: [email protected]
Blog: mesutakcan.blogspot.com
GitHub: mesutakcan
YouTube: Mesut Akcan

About

Enhanced Hotkey Control for AutoHotkey v2

www.autohotkey.com/boards/viewtopic.php?f=83&t=141073

Topics

ahkahk-scriptahk2classhotkeylibrary

Resources

Readme
MIT license
Activity

Stars

3 stars

Watchers

0 watching

Forks

0 forks
Report repository

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.