How 0x4133/snaklonger works
Project type and purpose
• This is a small CLI‐based Python utility (“Text Expander”) that hooks into OS keyboard events, watches what the user types, and replaces user‐defined abbreviations with full text snippets in real time.
• It is not a multi‐tier web app or microservice—it’s a single process script with a few logical modules.
File structure
• Top‐level files:
– main.py / main2.py: two entry‐point scripts (variants) containing the core logic
– expansions.txt: plain text datastore of “abbreviation:expansion” mappings
– longerPS.ps1: optional PowerShell helper script (likely for launching or installation)
– README.md: user documentation
• No “frontend” or “backend” folders—everything lives in one process
• No explicit tests or dev directories—focus is on runtime logic and data file
README for additional insights
• Libraries used: pynput (keyboard monitor & key simulation), pyperclip (clipboard ops)
• Flow described:
a. load_expansions() reads expansions.txt into an in‐memory dict
b. on_press() callback appends each key to a buffer
c. when space/enter detected, process_typed_text() checks buffer against abbreviations
d. if matched, simulate backspaces then “type” the expansion
Main components
a. OS Keyboard Events (external source)
b. Input Listener Module (pynput listener)
c. Typing Buffer Manager
d. Expansion Store Loader (reads expansions.txt → dict)
e. Text Processor (detect & match abbreviation)
f. Output Simulator (pynput to delete & type)
g. Clipboard Manager (pyperclip, if used for large text)
h. Optional Launcher (longerPS.ps1 or wrapper script)
Relationships & interactions
• OS Key Events → Input Listener → passes KeyEvent to Buffer Manager
• Buffer Manager accumulates characters until trigger key (space/enter) → invokes Text Processor
• Text Processor queries Expansion Store (in‐memory dict); if match found → calls Output Simulator
• Output Simulator issues backspace key events and types expansion (optionally via Clipboard Manager)
• Expansion Store Loader runs once at startup, then sits in memory
Highlighted architectural patterns & design principles
• Single‐process, event‐driven architecture (pynput’s callback model)
• Clear separation of concerns: I/O (keyboard), state management (buffer), data access (expansions.txt), processing logic, and output simulation
• Pluggable data source: expansions.txt can be replaced/extended without code changes
Detail
• Even for a small script, break it into these logical subcomponents
• Both the startup sequence (loading expansions) and the runtime loop (key events → expansion)
• Which third-party library implements each component (pynput, pyperclip)