This is a Python script that acts as a text expander, replacing predefined abbreviations with their corresponding expansions as you type. The script uses the pynput
library to monitor keyboard input and automatically expands abbreviations in real-time.
- Monitors keyboard input for predefined abbreviations.
- Replaces abbreviations with their expanded forms.
- Loads abbreviations and expansions from an external file.
- Simulates natural typing of the expanded text.
- Python 3.x
pynput
librarypyperclip
library
-
Clone the repository or download the script files.
-
Install the required libraries using pip:
pip install pynput pyperclip
-
Create an
expansions.txt
file in the same directory as the script with the following format:abbreviation:expansion
Example
expansions.txt
:brb:be right back omw:on my way idk:I don't know smh:shaking my head btw:by the way
-
Save the script to a file, for example,
text_expander.py
. -
Run the script from your terminal:
python text_expander.py
-
The script will start monitoring your keyboard input. When you type an abbreviation followed by a space or enter, it will replace the abbreviation with the expanded text.
load_expansions(file_path)
: This function reads the abbreviations and expansions from the specified file and returns a dictionary.on_press(key)
: This function is called every time a key is pressed. It appends the typed characters to a buffer and processes the text when a space or enter key is detected.process_typed_text()
: This function processes the typed text, checks if it matches any abbreviation, and replaces it with the expanded text by simulating backspace and typing the expanded text.
- To add or modify abbreviations and their expansions, edit the
expansions.txt
file. - Adjust the typing speed by modifying the sleep duration in the
process_typed_text()
function.
Contributions are welcome! Feel free to submit a pull request or open an issue to discuss improvements and enhancements.
This project is licensed under the MIT License. See the LICENSE file for details.
- This script uses the
pynput
library to monitor keyboard input and simulate key presses. - The
pyperclip
library is used for clipboard operations.
Disclaimer: This script is provided as-is. Use it at your own risk. The author is not responsible for any potential issues caused by the usage of this script.