Skip to main content

A cross-platform hot key module.

Project description

PyHotKey

Description

PyHotKey is a cross-platform hot key module for Python. Based on "pynput" library.

Installation

pip install PyHotKey

Usage

Importation:

from PyHotKey import manager, Key

Register:

a) prototype:

def RegisterHotKey(self, trigger, keys, count=2, interval=0.5, *args, **kwargs):
    """
    :param trigger: the function invoked when the hot key is triggered.
    :param list keys: the keystroke list.
    :param int count: the number of repeated keystrokes.
    :param float interval: the interval time between each keystroke, unit: second.
    :param args: the arguments of trigger.
    :param kwargs: the keyword arguments of trigger.
    :return: returns a key id if successful; otherwise returns -1.
    """
    pass

b) Example:

# combination hot key
key_id1 = manager.RegisterHotKey(func1, [Key.ctrl_l, Key.alt_l, 'z'])

# single keystroke hot key
key_id2 = manager.RegisterHotKey(func2, [Key.caps_lock], 2, 0.5,
                                 func2_arg1, func2_arg2=1)

Unregister:

result = manager.UnregisterHotKey(key_id1)

View hot key list:

print(manager.hotKeyList)

Logger:

# Turn on the logger
manager.logger = True

# custom the log path
manager.setLogPath('MyLog.log')

# Turn off the logger
manager.logger = False

Release Note

v1.3.3

Bug Fixes

  • Combination hot key: Fix the keystroke value error of combination hot key, temporarily adjust the pynput version to 1.4.5

Refactor

  • Simplify README.md.

v1.3.2

Bug Fixes

  • Log path: fix the default log path overwrites the custom log path when setting "manager.logger = True".

Refactor

  • Adjust code structure.
  • Rewrite README.md.

v1.3.1

  • Delete a deprecated class.
  • Replace root logger with a separate logger.
  • Rename property "hot_keys" to "hotKeyList".
  • Change documents and some code comments.

v1.3.0

  • Currently, users can customize the log path.
  • Optimize code.

v1.2.0

  • Add logger.
  • Optimize code.
  • Attempt to fix a potential bug.

v1.1.1

  • Remove log message.

v1.1.0

  • Currently, the trigger function supports arguments.
  • No longer need to call manager.start() manually.
  • Fix multiple type hot key bug.

v1.0

  • The first version.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyHotKey-1.3.3.tar.gz (8.3 kB view hashes)

Uploaded Source

Built Distribution

PyHotKey-1.3.3-py2.py3-none-any.whl (10.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page