The last typed keyboard entry gets modified if one of the two post modifier keys is pressed immediately after them. This script uses the keys "]" and "[" to cycle back and forth among the modified characters. These opposite directions are very useful for longer cycles. When you missed the right character, just use the other key to get back to it, instead of going through the whole list. The modifier keys appear only once in the script, so it is easy to replace them by other keys of your choice, like "\" and "`" (this later one is the escape character in the script, so it has to be repeated: "``").
If you want the modifier keys to act normally for just one time, press Esc beforehand, or any other key, like Space, which has no modifications, and delete its output (Backspace) afterwards. Exiting this instance of AutoHotKey restores the normal keyboard behavior until you restart the script.
You can extend or change the set of modified characters, changing the lines of character rings or adding new ones, as follows:
The Unicode character rings are stored in a text file, named UCring.txt. It has to be in the same directory as the script. Each line corresponds to a set of characters the post modifier keys cycle through (the character rings). The first character is the keyboard entry, the next one (separated by a comma ",") is the first modified version, and so on. If a Unicode character is needed, it has to be entered with its code in the form of {ASC xxx}.
The sample files contain math symbols, Greek, German and Hungarian letters. For other languages different diacritical letters can be used. (Don't put too many choices in one ring, because it will slow down your typing. The most often used ones should be close to the beginning or to the end.)
There are much fewer choices for ANSI characters, so the corresponding rings are put directly in the script. The only difference is that the character rings has to start with "x =" and the next line must be the conversion subroutine call: Gosub MakeRing.
The character rings are entered in the simplest possible format. To be able to process the keystrokes faster, a conversion is necessary. This can be done manually, too. Below the internal data structure is described:
Take the ASCI value of the key you want to produce modified versions. As an example let's use 97, the ASCI value of "a". The first constant, u97_0 is named as follows: "u" ("u" stands for Unicode, or in the other set "a" for ANSI) concatenated with this code and with the index "_0". Its value is the number of versions of "a", in our example below it is 4. The next constant is u97_1, the original character "a". The following entries, u97_2 …u97_4 are the modified versions, in our case they are "á", "ä" and "α". You have to use the Unicode code for the character "α" in the form of {ASC 945}, because it is not in the standard ASCI character set a script requires.
u97_0 = 4 ; number of character variants
u97_1 = a ; key to be modified
u97_2 = á ; second variant...
u97_3 = ä
u97_4 = {ASC 945}
The character codes can be found with the Windows Character Map. In Windows 2000 it is at
Start / Programs / Accessories / System Tools. It is cumbersome, though, because it gives you the hex codes instead of decimals. The Windows calculator can do the conversion, but the simple AutoHotKey script Unicodes.ahk will put directly the decimal codes and the corresponding characters in a Unicode text file, like what WordPad can create.
; Unicodes.ahk ; ; AutoHotkey Version: 1.x ; Language: English ; Platform: Win2000/XP ; Author: Laszlo Hars <www.Hars.US> ; ; Script Function: ; Tabulate code and Unicode characters ; ; Open a Unicode text file (e.g. WordPad File/New – option Unicode text) : don't change the active window until the script is done! ; Control+Alt+U starts a long loop of writing each code and Unicode character ; in separate lines ; Only the first 9743 Unicode characters are listed (the interesting ones) SetFormat integer,d ; decimal cnt = 256 ^!u:: Loop 9999 { code = `{ASC %cnt%`} Send %cnt% %code%`n cnt++ } return == == == == == == == == == == == == == ; SPkeys.AHK ; ; AutoHotkey Version: 1.x ; Language: English ; Platform: Win2000/XP ; Author: Laszlo Hars <www.Hars.US> ; ; Script Function: ; Help typing accented letters and special characters. ; A key followed by '[' or']' is replaced by special characters ; Use '[' to cycle forward, ']' to cycle backward among choices ; ; Requires the UCring.txt file with Unicode character ring descriptions ; in the same directory as this script ; ; Applications working with ANSI or Unicode are distinguished: ; SendMessage 0x55,,3,,A ; WM_NOTIFYFORMAT to the active window ; returns ErrorLevel 1 for ANSI, 2 for Unicode. (Thanks to Chris) ; (Exception: Notepad can handle Unicode but normally it uses ANSI) SetFormat integer, d ; decimal SetKeyDelay -1 ; no delay key0 = knum = cnt = 1 ; Unicode character rings Loop Read, %A_ScriptDir%\UCring.txt { StringMid key, A_LoopReadLine, 1, 1 Transform num, Asc, %key% StringSplit u%num%_, A_LoopReadLine, `, } u43_1 ={ASC 43} ; fix special '+' ; ANSI code character rings x = 1,¹ Gosub MakeRing x = 2,²,½ Gosub MakeRing x = 3,³ Gosub MakeRing x = 4,¼,¾ Gosub MakeRing x = 0,°,ø,Ø Gosub MakeRing x = -,–,— Gosub MakeRing x = $,€,£ Gosub MakeRing x = `%,‰ ; literal % Gosub MakeRing x = *,× Gosub MakeRing x = +,†,± Gosub MakeRing a43_1 ={ASC 43} ; fix special '+' x = e,é,æ Gosub MakeRing x = u,ú,ü,û Gosub MakeRing x = i,í,¦ Gosub MakeRing x = o,ó,ö,õ Gosub MakeRing x = p, Gosub MakeRing x = E,É,Æ Gosub MakeRing x = U,Ú,Ü,Û Gosub MakeRing x = I,Í Gosub MakeRing x = O,Ó,Ö,Õ Gosub MakeRing x = a,á,ä Gosub MakeRing x = s,ß,§ Gosub MakeRing x = f,ƒ Gosub MakeRing x = A,Á,Ä Gosub MakeRing x = b,ß Gosub MakeRing x = m,µ Gosub MakeRing x = .,•,… Gosub MakeRing x = /,÷ Gosub MakeRing x = <,‹,« Gosub MakeRing x = >,›,» Gosub MakeRing Loop ; process keystrokes { Input key, C L1 V IfEqual key, [, Gosub, Forward ; replace [-> your choice else IfEqual key, ], Gosub, Backward ; replace ]-> your choice else { key0 = %key% cnt = 1 } } Forward: ; Cycle through the character ring Gosub AnsiOrUniCode if %knum%_0 = return if (cnt >= %knum%_0) cnt = 1 else cnt++ x :=%knum%_%cnt% Send {Backspace 2}%x% return Backward: ; Cycle backward through the character ring Gosub AnsiOrUniCode if %knum%_0 = return if (cnt <= 1) cnt := %knum%_0 else cnt-- x :=%knum%_%cnt% Send {Backspace 2}%x% return AnsiOrUniCode: ; if foreground ap is Unicode, use arrays u..., else a... SendMessage 0x55,,3,,A Transform num, Asc, %key0% if ErrorLevel = 2 knum = u%num% else knum = a%num% return MakeRing: ; for ANSI code, x = characters in a ring StringMid key, x, 1, 1 Transform num, Asc, %key% StringSplit a%num%_, x, `, ; a->u for Unicode return