Skip to main content

Bind a global hotkey, on macOS, in Python

Project description

This is a set of minimal Python bindings for the undocumented macOS framework APIs that even the most modern, sandboxing-friendly shortcut-binding frameworks use under the hood for actually binding global hotkeys.

Unlike something full-featured like MASShortcut, this provides no configuration UI; you have to provide keyboard constants directly.

Simple example:

from quickmachotkey import quickHotKey, mask
from quickmachotkey.constants import kVK_ANSI_X, cmdKey, controlKey, optionKey

@quickHotKey(virtualKey=kVK_ANSI_X, modifierMask=mask(cmdKey, controlKey, optionKey))
def handler() -> None:
    print("handled ⌘⌃⌥X")

if __name__ == "__main__":
    from AppKit import NSApplication  # type:ignore[import]
    from PyObjCTools import AppHelper  # type:ignore[import]
    print("type ⌘⌃⌥X with any application focused")
    NSApplication.sharedApplication()
    AppHelper.runEventLoop()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quickmachotkey-2023.10.26.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

quickmachotkey-2023.10.26-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file quickmachotkey-2023.10.26.tar.gz.

File metadata

  • Download URL: quickmachotkey-2023.10.26.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for quickmachotkey-2023.10.26.tar.gz
Algorithm Hash digest
SHA256 5181c3404e2f27eca55b60b35cfb206e9a88488952d4787d1671fef8ccbdf12c
MD5 1262bdf667fb2c63e3d7553a59f1fafe
BLAKE2b-256 4d4432b9166cbd0abe6651d79ccefe60cd636a566e15dd8fc24931a507f5a215

See more details on using hashes here.

File details

Details for the file quickmachotkey-2023.10.26-py3-none-any.whl.

File metadata

File hashes

Hashes for quickmachotkey-2023.10.26-py3-none-any.whl
Algorithm Hash digest
SHA256 98f60f01ac251ca7a1dcccc94788965e3e99c607390f9f7b3f297a887cc60647
MD5 9abbbc1c507b7740e426c9277379a854
BLAKE2b-256 123c5cb1d06938821b66c2fed1fa1320ab3d827a3344fb9fd781f3393ba90d1d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page