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.10.26.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5181c3404e2f27eca55b60b35cfb206e9a88488952d4787d1671fef8ccbdf12c |
|
MD5 | 1262bdf667fb2c63e3d7553a59f1fafe |
|
BLAKE2b-256 | 4d4432b9166cbd0abe6651d79ccefe60cd636a566e15dd8fc24931a507f5a215 |
Close
Hashes for quickmachotkey-2023.10.26-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98f60f01ac251ca7a1dcccc94788965e3e99c607390f9f7b3f297a887cc60647 |
|
MD5 | 9abbbc1c507b7740e426c9277379a854 |
|
BLAKE2b-256 | 123c5cb1d06938821b66c2fed1fa1320ab3d827a3344fb9fd781f3393ba90d1d |