Skip to content

Python script to translate text that was typed accidentally in wrong keyboard layout (like PuntoSwitcher)

License

Notifications You must be signed in to change notification settings

alexantoshuk/kbdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KBDF

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


Install

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.


Example Usage

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


How it works

Simple!

  1. Backup current clipboard content.
  2. Emit shift+home for line selection (in 'line' mode only).
  3. Emit ctrl+c to copy selection to clipboard.
  4. Get clipboard content and translate text word by word.
  5. Write translated text to clipboard.
  6. Emit ctrl+v to replace selection with clipboard content.
  7. Restore clipboard content from backup.

Limitations

  • 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.

Alternatives

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.

PuntoSwitcher (Windows only)
XNeur (Linux only)

About

Python script to translate text that was typed accidentally in wrong keyboard layout (like PuntoSwitcher)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published