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
File details
Details for the file quickmachotkey-2023.3.4.tar.gz
.
File metadata
- Download URL: quickmachotkey-2023.3.4.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 024475f6117b64ceb883f360ff823356070d5dc6dd6a838c9b23bea0abdaf4fb |
|
MD5 | a89a7677d2c2d381c633d0bc488b9d9b |
|
BLAKE2b-256 | d96cca7eae860a157fc028d011af547d03ac21c0a61fd6e515d6663d52341f56 |
File details
Details for the file quickmachotkey-2023.3.4-py3-none-any.whl
.
File metadata
- Download URL: quickmachotkey-2023.3.4-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76a02c5920b112a3a9f6267cafd572b10bdd752ee4467d29e51806193380d8da |
|
MD5 | b76129f40ed6b3c444e323446155d7a4 |
|
BLAKE2b-256 | 34a4af6a45e2f2a54f4486a32fd0dd6e452bf14a91c8e5fb5e0e4b1d49b60482 |