A cross-platform Python tool that allows you to capture a selected region of your screen using a hotkey, send it to a Large Language Model (LLM) via the OpenRouter API for Optical Character Recognition (OCR), and automatically copy the extracted text to your clipboard.
- Hotkey Activation: Trigger screen capture with a configurable global hotkey (Default:
Ctrl+Win+Eon Windows,Ctrl+Super+Eon Linux,Ctrl+Cmd+Eon macOS). - Region Selection: An overlay allows you to precisely select the screen area for OCR.
- LLM-Powered OCR: Leverages powerful Vision Language Models via OpenRouter for potentially higher accuracy OCR compared to traditional methods.
- OpenRouter Integration: Easily switch between different compatible models supported by OpenRouter.
- Clipboard Output: Extracted text is automatically copied to the clipboard for immediate use.
- Configurable Logging: Enable/disable detailed file logging via the
.envfile for debugging. - Cross-Platform Attempt: Includes default hotkey configurations for Windows, macOS, and Linux.
- (Optional) Build Executable: Can be packaged into a standalone executable using PyInstaller.
- Python: 3.8+ recommended.
- pip: Python package installer.
- OpenRouter API Key: You need an account and API key from OpenRouter.ai.
-
Clone the repository:
git clone https://github.com/cherjr/screen-ocr-llm.git cd screen-ocr-llm -
Install dependencies:
pip install -r requirements.txt
(Optional: It's recommended to use a Python virtual environment)
# Example using venv python -m venv venv # Activate (Windows Powershell) .\venv\Scripts\Activate.ps1 # Activate (Linux/macOS Bash) # source venv/bin/activate pip install -r requirements.txt
-
Create
.envfile: Copy the example file:# Windows copy .env.example .env # Linux/macOS # cp .env.example .env
Now, edit the
.envfile with your actual credentials and preferences.
Edit the .env file to configure the tool:
OPENROUTER_API_KEY: (Required) Your API key obtained from OpenRouter.ai. Keep this secret!MODEL: (Required) The identifier for the OpenRouter model you want to use. Must be a model compatible with image input (Vision Language Model). You can find available models on the OpenRouter site. Example:qwen/qwen2.5-vl-72b-instruct:freeENABLE_FILE_LOGGING: (Optional) Set toTrueto enable detailed logging toscreen_ocr_debug.login the application's directory. Set toFalseor omit to disable logging. Useful for debugging.
-
Run the script:
python screen-ocr-llm.py
The script will run in the background and listen for the hotkey. You'll see log messages in the console (or the log file if enabled).
-
Press the Hotkey:
- Windows:
Ctrl + Win + E - Linux:
Ctrl + Super + E(Super is often the Windows key) - macOS:
Ctrl + Command + E
- Windows:
-
Select Region: Your screen will dim slightly. Click and drag your mouse to draw a rectangle around the area you want to OCR. Release the mouse button.
-
Get Text: The script will capture the selected region, send it to the configured OpenRouter model, and copy the extracted text to your clipboard. You can then paste the text anywhere.
-
Stop the script: Press
Ctrl + Cin the terminal where the script is running.
You can create a standalone .exe file for Windows using PyInstaller.
-
Install PyInstaller:
pip install pyinstaller
-
Build the executable: Run this command from the script's directory:
pyinstaller --onefile --windowed --name ScreenOCRTool screen-ocr-llm.py
-
Prepare for Distribution:
- The executable will be in the
distfolder (dist/ScreenOCRTool.exe). - Crucially, copy your
.envfile into thedistfolder next to the executable. The.exeneeds this file to run correctly.
- The executable will be in the
-
Run: Double-click
ScreenOCRTool.exe. It will run silently in the background.
To make the tool run automatically when you log in:
- Windows:
- Create a shortcut to the
.exe(located in its permanent folder alongside.env). - Press
Win + R, typeshell:startup, press Enter. - Paste the shortcut into the Startup folder that opens.
- Alternatively: Use Task Scheduler for more control (configure it to run the
.exeat logon, making sure to set the "Start in" directory to the folder containing the.exeand.env).
- Create a shortcut to the
- macOS: Use
launchd(create a.plistfile). - Linux: Use your desktop environment's autostart settings or systemd user services.
- Hotkey Not Working:
- Ensure the script is running in the background.
- Check if another application is using the same hotkey combination. Try changing the
HOTKEY_CONFIGin the script temporarily to test. - Some systems/permissions might interfere with global hotkeys.
- Errors / No Text Copied:
- Check your internet connection.
- Verify your
OPENROUTER_API_KEYis correct in the.envfile. - Ensure the specified
MODELin.envis valid and supports image input on OpenRouter. - Check your OpenRouter account for any API limits or billing issues.
- If built into an
.exe, ensure the.envfile is in the same directory as the.exe.
- Debugging: Set
ENABLE_FILE_LOGGING=Truein your.envfile and checkscreen_ocr_debug.log(created in the same directory as the script/exe) for detailed error messages after trying to use the tool.
This project is licensed under the MIT License - see the LICENSE file for details.
This tool relies on several fantastic libraries:
- mss: For screen capture.
- pynput: For global hotkey listening and control.
- requests: For making API calls.
- python-dotenv: For loading environment variables.
- pyperclip: For cross-platform clipboard operations.
- Tkinter (built-in): For the region selection GUI.