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.11.17.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

quickmachotkey-2023.11.17-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for quickmachotkey-2023.11.17.tar.gz
Algorithm Hash digest
SHA256 b29c8a6606400bd3afbbb26b1d2f3e791e9ccab2727530c8df38c14225298de5
MD5 5bfd63bd6913247e9e3d8a0114cdae89
BLAKE2b-256 e20df1776216c0148636a5f6fb8764cc77376422687fec99a77847aa30908dc4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for quickmachotkey-2023.11.17-py3-none-any.whl
Algorithm Hash digest
SHA256 d206c558ed3087841c9ab318b099d5c1e1a61f4601ad6b3c1327691b2749d81f
MD5 c941181e9059a716cf0a3f41b9cec57a
BLAKE2b-256 462a659282e03752c60aa73019228a09b8d43d759ed988ff1c9a2e933bb02dbb

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