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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for quickmachotkey-2023.3.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76a02c5920b112a3a9f6267cafd572b10bdd752ee4467d29e51806193380d8da |
|
MD5 | b76129f40ed6b3c444e323446155d7a4 |
|
BLAKE2b-256 | 34a4af6a45e2f2a54f4486a32fd0dd6e452bf14a91c8e5fb5e0e4b1d49b60482 |