Skip to main content

System Hotkey

Multi platform system wide hotkeys for python 3,

Currently no mac or python2 support :(

Installation

the old

pip3 install system_hotkey

should do the trick

Windows

install pywin32

Linux

For x11 you should use xcffib (bsd license), Also xpybutil is required.

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.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

Authors and Contributors

Timothy Eichler

Release files for system-hotkey 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for system-hotkey 1.0.4
File Size Uploaded
system_hotkey-1.0.4.tar.gz 31.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for system-hotkey 1.0.4
File Interpreter ABI Platform
system_hotkey-1.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 63.0 kB

Release files / system_hotkey-1.0.4.tar.gz

Download URL system_hotkey-1.0.4.tar.gz
Size 31.9 kB
Tags Source
SHA-256 checksum
How to use checksums
104e60b2af0fac51e0c7bcbb7dc59e349ab873d2c6dcb04d6d6a81ca0959965e
BLAKE2b-256 checksum
How to use checksums
c76ee92452de49e8f7fcaacb4edc3826bef885c1fb84d7b831d92a27e4f37045
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release files / system_hotkey-1.0.4-py3-none-any.whl

Download URL system_hotkey-1.0.4-py3-none-any.whl
Size 31.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7a2abfa63e828f5017a5c941b9c9fd9549c5b69f8257329fe78f994505a20e7
BLAKE2b-256 checksum
How to use checksums
ad95120e71ecdc1b2115df08b0c335c7b79fb3051647d8c753c9be8c5c9160e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release history Release notifications | RSS feed

This release

1.0.4 This release

2 release files

1.0.3

1 release file

1.0.2

2 release files

1.0.1

2 release files

1.0.0

0.1.4.1

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page