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.11.17.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b29c8a6606400bd3afbbb26b1d2f3e791e9ccab2727530c8df38c14225298de5 |
|
MD5 | 5bfd63bd6913247e9e3d8a0114cdae89 |
|
BLAKE2b-256 | e20df1776216c0148636a5f6fb8764cc77376422687fec99a77847aa30908dc4 |
Close
Hashes for quickmachotkey-2023.11.17-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d206c558ed3087841c9ab318b099d5c1e1a61f4601ad6b3c1327691b2749d81f |
|
MD5 | c941181e9059a716cf0a3f41b9cec57a |
|
BLAKE2b-256 | 462a659282e03752c60aa73019228a09b8d43d759ed988ff1c9a2e933bb02dbb |