User:Любослов Езыкин/Compose key with AutoHotkey

From Wikipedia, the free encyclopedia

Compose key in GNU/Linux[edit]

In GNU/Linux distributions (Ubuntu, Linux Mint, etc.) there is a very convenient tool as the "Compose key" that allows you to enter any extra letters and symbols (like ç á ä å « », practically anything) without installing any additional software or keyboard layouts. For example, to get letters ⟨ö⟩, ⟨æ⟩, ⟨ç⟩ you just type Compose key+o+", Compose key+a+e, Compose key+c+,. You can assign any keyboard button for the Compose key (say, F12: in this case you type F12+o+" for ⟨ö⟩).

This is a instruction of how to do this sort of things in Windows OS in 5 simple steps.

Step 1. Understanding AutoHotkey[edit]

AutoHotkey is a Windows-based scripting language that allows you to create keyboard shortcuts. You can read the article and manual, but for now you just need to know that it is some sort of program that interprets and executes scripts created by you. You install a program autohotkey.exe, then create your own script your_script.ahk, then run the script by left-clicking.

Step 2. Installing AutoHotkey[edit]

Go to the official site autohotkey.com, download and install the program to your system (read and follow the instructions, if something is not clear).

Step 3. Understanding the "Hotstrings and Auto-replace" functions[edit]

See the full instruction. This function allows you to enter some letters (a string) and the script substitutes them for others. In the example from above you write in your script:

::btw::by the way

Then run the script and when you enter btw you'll get "by the way".

So for ⟨ö⟩ and ⟨ç⟩ you can create:

::o"::ö
::c,::ç

Then run the script and when you enter o" and c, you'll get ⟨ö⟩ and ⟨ç⟩.

Though there are some complications. If you type Boo"tes and Curac,ao you won't get Boötes and Curaçao, because the script requires a space before and after the combination, that is you need to type Bo o" tes and Cura c, ao which generates Bo ö tes and Cura ç ao.

To override this problem add before the lines of your code ?, to allow the scripts working inside words, and *, to allow the script working without an ending character.

So

:?*::o"::ö
:?*::c,::ç

Then run the script, type Boo"tes and Curac,ao and you will get Boötes and Curaçao.

Step 4. Assigning the Compose key[edit]

If you need only a small amount of additional characters you can just leave the script as is. Say, you only occasionally type in German and Spanish then you create a script:

:?*::a"::ä
:?*::o"::ö
:?*::o"::ü
:?*::sz::ß
:?*::a'::á
:?*::e'::é
:?*::i'::í
:?*::o'::ó
:?*::u'::ú
:?*::n~::ñ

But even this small and simple script may cause problems. When you type "America", America's or Liszt you'll get "Americä, Americás and Lißt. So you need to pause the script any time when you do not want enter additional characters. To override this problem we manually introduce the pseudo-"Compose key". You can't actually assign any keyboard button for the "Compose key" in this script (or, at least, I personally do not know how) but you can assign any ASCII character. I personally prefer to use = because it is very easy to type (you do not need to press ⇧ Shift) and this symbol is rarely used in texts. Of course, you can assign anything else you want (say, % or #). Now we slightly modify our script:

:?*::=a"::ä
:?*::=o"::ö
:?*::=o"::ü
:?*::=sz::ß
:?*::=a'::á
:?*::=e'::é
:?*::=i'::í
:?*::=o'::ó
:?*::=u'::ú
:?*::=n~::ñ

In this case to type an additional character we first type = and then the combination. E.g. Bo=o"tes and Cura=c,ao generate Boötes and Curaçao. You also do not need to pause the script, now "America" and America's won't change. This works exactly the same as the "Compose key" in GNU/Linux systems.

Step 5. Creating your scripts[edit]

Finally, when we understand how it all works we can create our script. I advise to create a special folder like C:\YOUR_HOME_FOLDER\AHKscripts and keep your scripts there. Then create a text file and name it as you wish (say, German-Spanish.ahk). You script must end in .ahk otherwise it won't work. Edit your script with any text editor (I advise Notepad++) and enter your code (like above) and save the script. Important: You must save it in UTF-8 (in Notepad++ menu Encoding > Convert to UTF-8). Now start the script and work with it. You can make it run automatically at Start-up[1][2].

Examples[edit]

Latin[edit]

This is the code of my script. It is for practically every European language plus transliteration for Arabic, Devanagari and Chinese. You can modify it as you wish.

Note #1: ; defines comments.

Note #2: ` cannot be used as it's the default escape character in AutoHotkey.[3] Hence \ for a grave accent. But this can be escaped by using the double `` in the script, that in fact signifies one pressing of `.

Note #3: Some characters have two alternative ways.

Cyrillic[edit]

Arabic[edit]

Note: !0::Suspend is a command for an easy off/on with Alt+0 (see [4][5]).