A keyboard listener that allows for custom combinations and keywords to trigger custom functions
Project description
keyboard_listener
Keyboard Listener is a module that allows you to create custom hotkeys (combinations) or custom keywords and bind them to custom functions in Python. It's really easy to use and can be installed via pip:
pip install keyboard_listener
Combinations are custom hotkeys that are bound to functions. When the combination is pressed, the function is executed. Combos are really easy to set up and can be seen in the example below.
Keywords are custom strings that when entered (or rather, when their characters are entered in sequence) trigger a function to be executed. Keywords are also shown in the example below.
KeyboardListener object needs to be instantiated with the custom combinations and custom keywords dictionaries before running. Please refer to the below example to see how to set those up. If no dictionaries are passed, the program will assume no combinations or keywords are set up.
Example:
from keyboard_listener import KeyboardListener, Combo, KeyWord
def function_1(arguments):
# do something
def function_2(arguments):
# do something else
combinations = {
'function 1': Combo(['alt'], 'f', function_1, arguments),
#Function 1 is executed when the user presses Alt+F
'function 2': Combo(['ctr','alt'], 'g', function_2, arguments),
#Function 2 is executed when the user presses Alt+G
'function 3': Combo(['shift','alt'], 'H', function_2, arguments),
#Be mindful when setting up Combos that include 'shift'. If the Combo includes the shift key, the character must be uppercase.
}
keywords = {
'keyword_1': KeyWord('keyword1', function_1, arguments),
#Function 1 is executed when the user types 'keyword1'
'keyword_2': KeyWord('keyword1', function_2, arguments)
#Function 2 is executed when the user types 'keyword2'
}
keyboard_listener = KeyboardListener(combinations=combinations, keywords=keywords)
keyboard_listener.run()
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
Built Distribution
Hashes for keyboard_listener-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9c39ba00baba4cce985574c70989adf734801bfa8a8086e6febf380640f3cb8 |
|
MD5 | 0a310fbc95e86ff6062c3d2c495c8b5f |
|
BLAKE2b-256 | db835ecf11f848af7812fa09dc0ef3a679760745d52b2ec8537ce99dbae55803 |