kbdf is a simple python script to translate text that was typed accidentally in wrong keyboard layout.
For now its only support Russian and English keyboard layouts
kbdf supports Python3 on Linux and Windows.
You can install it using pip:
pip install git+https://github.com/alexantoshuk/kbdf
Or manually download kbdf.pyw and make it executable:
cmod +x kbdf.pyw
...and install python dependencies:
pip install pyautogui
pip install pyperclip
Also Linux needs the xclip
installed.
On Linux: just bind it to some hotkey.
On Windows: you can use AutoHotkey and put caps.ahk and kbdf.ahk to autostart.
kbdf.pyw line
- translate last typed line, or selection if exists (default)
kbdf.pyw selection
- translate selected text
Simple!
- Backup current clipboard content.
- Emit shift+home for line selection (in 'line' mode only).
- Emit ctrl+c to copy selection to clipboard.
- Get clipboard content and translate text word by word.
- Write translated text to clipboard.
- Emit ctrl+v to replace selection with clipboard content.
- Restore clipboard content from backup.
- For now it can switch only between Russian and English keyboard layouts.
- Doesn't work under Wayland on Linux.
- It doesn't work in the terminal (except if terminal support to select line by shift+home and copy/paste by ctrl+c ctrl+v).
- Undefined behavior when bind this script to hotkeys with super modifier.
The alternatives is much more functional. But goal of this project is simplicity, stability, work on Linux and Windows. And in my opinion, automatic switching creates more problems than it solves, so in kbdf there is no such possibility.