System wide hotkeys
Project description
System Hotkey 310
Multi platform system wide hotkeys for Python 3.10+
Currently no mac support but pull requests or collaboration is very welcome!
Note: currently this fork of system_hotkey exists just to fix Python 3.10 compatibility.
Installation
the old
pip3 install system_hotkey310
should do the trick
Windows
install pywin32
Linux
For x11 you should use xcffib (bsd license),
If for some reason you have to use the python xlib bindings (gpl license), a few fixes need be added first. See here
Usage
Input Keysyms
System hotkeys uses the keysym names from xlib for everything besides modifiers.(although case insensitive) grep for vk_codes for a list of available chars. If you are unable to bind to a certain key please let us know.
You can bind directly to symbols such as [”’,. etc Numpad keys can be binded by prefixing with kp_.
Supported modifiers include:
control
shift
super (windows key)
alt
InvalidKeyError will be raised if a key was not understood
from system_hotkey import SystemHotkey
hk = SystemHotkey()
hk.register(('control', 'shift', 'h'), callback=lambda x: print("Easy!"))
A SystemRegisterError will be raised if a hotkey is already in use.
To unregister a hotkey
hk.unregister(('control', 'shift', 'h'))
A KeyError will be raised if the combination is not already grabbed.
A UnregisterError will be raised if unregistering failed for any other reason.
If you want you can pass in a custom consumer:
def some_func(self, event, hotkey, args):
pass
hk = SystemHotkey(consumer=some_func)
hk.register(hotkey, arg1, arg2, arg3)
So you have a master function that receives all hotkey presses and can delegate as desired.
Note Modifier keys are independent of order i.e control + alt + del is the same as alt + control + del
Features
Support for up to 3 modifiers and a key
Limitations
I have only mapped most common keys, i have not experimented with Unicode/Japanese characters etc. It’s only a matter of mapping a name to the keysym on Linux and virtual key code on windows.
binding to kp_left (key pad left) will also bind to kp_4, there is a flag (unite_kp) to toggle this behaviour but it is experimental
Requires an xserver (x11)…
To be done
Mac support
eta > 8 months
Version Release Notes
1.0.5
Python 3.10 compatibility
1.0.4
Exceptions are now run in main
1.0.3
Documented the fact that xlib shouldn’t really be used
1.0.2
Fixed a linux bug where spurious events got passed through
1.0.0
calls to the unregister and register are now thread safe
kp keys work properly
kp_unite option
0.1.4
Bug fix on linux where pressing numlock would crash us..
0.1.3
Custom args can now be passed to a custom consumer
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 system_hotkey310-1.0.5.tar.gz
.
File metadata
- Download URL: system_hotkey310-1.0.5.tar.gz
- Upload date:
- Size: 32.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84d160a678e5afae53bca59f647433e9aefb402f80302f5f8e1479231227abab |
|
MD5 | 77e789b0ce74e380e99f96190282a483 |
|
BLAKE2b-256 | ee6e4c428fe0720d863c53ad13477cf1dea0d0bb9fe2775652dbd95fa9e9602b |
File details
Details for the file system_hotkey310-1.0.5-py3-none-any.whl
.
File metadata
- Download URL: system_hotkey310-1.0.5-py3-none-any.whl
- Upload date:
- Size: 31.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4fd85d9ea5cac7d949421b945e718b80997eb08578627c809eef9adc219c0c7 |
|
MD5 | fb2875e55b83e180fa1cc806b77c7eb4 |
|
BLAKE2b-256 | 9e77f0190b70abf886a328ea318e13bb571ffff880a60ad299cdc0c9dca84348 |