Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

84 Commits

Repository files navigation

Keyboard Handler

Cross-platform global hotkey handler for Python with human-readable key parsing.

Platform Support

  • Windows: WX-based via wx.RegisterHotKey() or direct via pywin32
  • Linux: AT-SPI via pyatspi
  • macOS: Carbon/AppKit (partial support)

Installation

pip install keyboard_handler
# Windows only:
pip install keyboard_handler[':sys_platform == "win32"']

Usage

WXKeyboardHandler

fromkeyboard_handler.wx_handlerimportWXKeyboardHandlerhandler=WXKeyboardHandler(parent)
# Register a hotkeyhandler.register_key("control+t", self.display_time)
handler.register_key("control+win+w", self.do_something_else)
# Register multiple hotkeysmapping= {
"control+w": self.close_window,
"alt+f4": self.close_all
}
handler.register_keys(mapping)
# Unregisterhandler.unregister_key("control+t", self.display_time)
handler.unregister_keys(mapping)
handler.unregister_all_keys()

Error Handling

fromkeyboard_handlerimportKeyboardHandlerErrortry:
handler.register_key("control+t", callback)
exceptKeyboardHandlerError:
# Key already registered or parse errorpass

Key Format

Keys use + to separate modifiers from the main key:

  • Modifiers: control, shift, alt, win (or windows)
  • Examples: "control+t", "shift+alt+f1", "control+win+delete"

About

easily parse and register hotkeys on multiple platforms

Resources

Stars

4 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages