Skip to main content

Keyhac 2

Python-scriptable keyboard customization for Windows and macOS.

Keyhac installs a system-wide keyboard hook and lets you script what your keys do in Python. You write one file, ~/.keyhac/config.py, and it runs unchanged on both OSes — remapping keys, binding keys to Python functions, and driving windows, applications and the clipboard from the keyboard.

Keyhac 2 replaces the two previous-generation products, Keyhac for Windows (1.x) and Keyhac for macOS (1.x), rebuilt as one shared codebase. Those older versions are no longer developed — if you are coming from one of them, see the migration guides in Documentation below. Keyhac 2's UI is built on PuiKit.

Features

  • Key remapping: key → key, key → key sequence, key → Python function.
  • Per-application key tables: match by app name, window title, Win32 window class, or the full accessibility focus path (AX on macOS, UI Automation on Windows) — down to "only in this app's text editor pane".
  • User modifiers: turn any key into a modifier of your own (User0–User3), invisible to applications.
  • One-shot modifiers: tap a modifier alone for one action, hold it to modify.
  • Multi-stroke key tables: Emacs-style prefix keys, with a balloon showing the armed prefix.
  • Clipboard history: persistent history in a popup chooser — type to filter, Enter pastes into the app you came from. Plus fixed snippets and scriptable clipboard-transform tools.
  • Window control: move, snap/tile, minimize, activate and launch applications, multi-monitor aware.
  • Keyboard macros: record and replay keys.
  • Mouse output: send clicks, wheel scrolls and pointer moves from key bindings.
  • Console window: live log, last-key and focus-path inspector — see exactly what to bind. Runs from the system tray (Windows) / menu-bar extra (macOS).

Screenshots

Console (macOS) Console (Windows)
Keyhac console window on macOS: keyboard-hook toggle, log level selector, live key-event log, last-key and focus-path inspector Keyhac console window on Windows: keyboard-hook toggle, log level selector, live key-event log, last-key and focus-path inspector
Menu-bar extra (macOS) Task tray (Windows)
Keyhac menu-bar extra on macOS with its menu open: Open Console, Edit Config, Reload Config, Keyboard Hook, Quit Keyhac Keyhac task-tray icon on Windows with its menu open: Open Console, Edit Config, Reload Config, Keyboard Hook, Quit Keyhac

Install

  • macOS 15+ — download Keyhac-<version>-macos.dmg from Releases: drag Keyhac.app into Applications and launch it. Grant the Accessibility permission when prompted (required for the keyboard hook).
  • Windows 10/11 (x64) — install from the Microsoft Store (or winget install --id 9P8H1PG6PRHH --source msstore) — automatic updates, no SmartScreen warning. Alternatively, download Keyhac-<version>-win64.zip from Releases, unzip anywhere and run Keyhac.exe.

Details, data locations and privacy notes: doc/installation.md.

Quick start

On first run Keyhac creates ~/.keyhac/config.py from a fully commented template. Open it from the tray / menu-bar icon ("Edit Config"), edit, then "Reload Config". A config defines one function:

from keyhac import *

def configure(keymap):
    kt = keymap.define_keytable(focus_path_pattern="*")   # active everywhere

    kt["Fn-J"] = "Left"                        # key -> key
    kt["Fn-A"] = "Home", "Shift-End"           # key -> sequence

    def hello():                               # key -> Python function
        print("Hello from config.py")
    kt["Fn-H"] = hello

    kt["Fn-V"] = ShowClipboardHistory()        # clipboard history popup

    kt_browser = keymap.define_keytable(app="chrome|Safari")   # per-app table
    kt_browser["Fn-R"] = "Cmd-R"

The full guide is doc/configuration.md, the per-symbol reference doc/config-api.md; the shipped template (keyhac/_config.py) is a working tour of every feature.

Documentation

Running from source

python3 -m venv .venv
.venv/bin/pip install -e ".[dev]"
.venv/bin/python -m pytest          # engine + unit tests, no permissions needed
.venv/bin/python -m keyhac          # run (macOS: needs Accessibility permission)

python -m keyhac -d enables debug logging, --no-ui runs headless (hook + engine only), --config PATH uses an alternate config file (its data files live beside it).

Contact & Support

License

MIT — see LICENSE.

Metadata

Release files for keyhac 2.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for keyhac 2.2.2
File Size Uploaded
keyhac-2.2.2.tar.gz 284.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for keyhac 2.2.2
File Interpreter ABI Platform
keyhac-2.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 592.0 kB

Release files / keyhac-2.2.2.tar.gz

Download URL keyhac-2.2.2.tar.gz
Size 284.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e0c1c5f13bc8e65f3728d5fc9aad5d426fa9449cf4ac4a76f299e5f9b3705c31
BLAKE2b-256 checksum
How to use checksums
1cc5d2b79282653f0aa19f5b48fb66603ce3374234767c9b7dddbf756d5ba52f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / keyhac-2.2.2-py3-none-any.whl

Download URL keyhac-2.2.2-py3-none-any.whl
Size 307.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dd8c4f7bede772cc45fb6168f03186307ce6242c1088ee2dcedd356e754209cf
BLAKE2b-256 checksum
How to use checksums
3c4ded74b6675eb814beac97994cef78f39393ca521fab6dd34d6c8eeb6be322
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release history Release notifications | RSS feed

2.4.2

2 release files

2.4.1

2 release files

2.4.0

2 release files

2.3.0

2 release files

2.2.3

2 release files

This release

2.2.2 This release

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page