Auto-correct text entered with the wrong keyboard layout

 

To enter text in some languages you press a special key combination (e.g. Alt-Shift) to toggle the keyboard layout. The keyboard layout context is typically kept separately for each window. This is generally good, but forces you to remember (or check) the current layout every time you switch to another window. If you forget to do that, the text you type will come out as gibberish. To me this happens often enough that I automated the fixing of such text.

I do this by programming AutoHotKey with a script that fixes the selected text my mapping it to the correct character set. For example, if you have written Ιτ ςασ α δαρκ ανδ στορμυ νιγητ it will replace it with It was a dark and stormy night. If you have written Mia for;a ki ;enan kair;o it will replace it with Μια φορά κι έναν καιρό.

The script

  • copies the selected text to the clipboard,
  • obtains a copy of the clipboard (to minimize system calls),
  • detects the direction of the desired mapping (Greek to Latin or Latin to Greek),
  • converts sequences that include a stress dead key combination,
  • converts all other characters,
  • sets the clipboard to the mapped text, and
  • pastes the text to the current selection.

I automated the creation of the AutoHotKey script with a Python script. I assume this can also be useful for text that is entered through other switched keyboard layouts, such as Cyrillic or Hebrew. Contributions are welcomed via pull requests to the code’s GitHub repository.

Comments   Toot! Share


Last modified: Tuesday, July 21, 2020 3:16 pm

Creative Commons Licence BY NC

Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.