Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Key post-modifier for fast typing special characters


  • Please log in to reply
14 replies to this topic
Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
There is a simple way doing post-modifications of keyboard keys in AutoHotKey, using subroutines and arrays. The script below recognizes if the foreground application uses Unicode (like MS Word) or ANSI fonts, and uses different set of character rings accordingly.

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


Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
",{ASC 8243},{ASC 8220},{ASC 8221},{ASC 8222}
$,€,£
%,‰
',{ASC 8242},{ASC 8216},{ASC 8217},{ASC 8218},{ASC 8219}
*,×
+,±,†,{ASC 8225}
-,{ASC 8722},–,—
.,·,{ASC 8226},{ASC 9702},{ASC 9679},{ASC 9675},{ASC 9642},{ASC 9643},{ASC 9632},{ASC 9633},{ASC 9674},…
/,{ASC 8725},÷
0,°,{ASC 9702},{ASC 9675},{ASC 9679},ø,Ø
1,¹
2,²,½
3,³,{ASC 8531},{ASC 8532}
4,¼,¾
8,{ASC 8539},{ASC 8540},{ASC 8541},{ASC 8542}
<,{ASC 8804},‹,«,{ASC 8592},{ASC 9668}
=,{ASC 8800},{ASC 8801},{ASC 8596}
>,{ASC 8805},›,»,{ASC 8594},{ASC 9658}
A,Á,Ä,{ASC 8745},{ASC 1488}
D,{ASC 916}
E,É,Æ
F,{ASC 934}
G,{ASC 915}
I,Í,{ASC 8747}
L,{ASC 923},{ASC 8735}
O,Ó,Ö,{ASC 937},{ASC 336}
P,{ASC 928},{ASC 936},{ASC 8719}
R,{ASC 8730}
S,{ASC 931},{ASC 8721}
T,{ASC 920}
U,Ú,Ü,{ASC 368}
X,{ASC 926}
^,{ASC 8593},{ASC 8595},{ASC 8597},{ASC 9650}
_,{ASC 8254}
a,á,ä,{ASC 945}
b,{ASC 946}
d,{ASC 948}
e,é,æ,{ASC 949},{ASC 951}
f,ƒ,{ASC 966}
g,{ASC 947}
h,{ASC 967}
i,í,¦,{ASC 953}
k,{ASC 954}
l,{ASC 955}
m,µ
n,{ASC 8319},{ASC 957}
o,ó,ö,{ASC 969},{ASC 337}
p,{ASC 960},{ASC 968},¶
r,{ASC 961}
s,ß,{ASC 962},§
t,{ASC 964},{ASC 952}
u,ú,ü,{ASC 369}
v,{ASC 9660}
w,{ASC 969}
x,{ASC 958},{ASC 967}
z,{ASC 950}
~,{ASC 8776},{ASC 8734}

BoBo
  • Guests
  • Last active:
  • Joined: --
Stunned. :shock:
That looks coooool. 8)
Thx for sharing it. :D

jonny
  • Members
  • 2951 posts
  • Last active: Feb 24 2008 04:22 AM
  • Joined: 13 Nov 2004
Without code tags:

Msgbox, This script is hard to read!
Gui,Add,Text,,It's also lost it's indentation!
Gui,Show
return

With code tags:

Msgbox, Ah, much better!
Gui,Add,Text,,Thank you, code tags!
   Gui,Show
SoundPlay, jingle.wav
return

[code][/code]


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Since the indentation was already there, I added the code tags.

Nice script and explanation!

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
I updated the AutoHotKey script for fast typing special characters. The description of the project and the SW design is in http://www.hars.us/P...tKey-script.doc or in http://www.hars.us/P...tKey-script.pdf. The script http://www.hars.us/SW/skey.ahk needs also two character ring description text files: http://www.hars.us/SW/ACring.txt and http://www.hars.us/SW/UCring.txt, for ANSI and for Unicode character substitutions. They have to be copied to the same directory as the script, which provides the character substitution function when started. The simple http://www.hars.us/SW/unicodes.ahk script helps figuring out the decimal character codes, in case you want to modify the character substitution rings. The result, somewhat edited, is in the http://www.hars.us/SW/unicodes.txt, to be viewed in WordPad, or a similar application working well with Unicode.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

The description of the project and the SW design is in http://www.hars.us/P...tKey-script.doc or in http://www.hars.us/P...tKey-script.pdf.

Thanks for the links. Your research, instructions, and scripts for Unicode, character mapping, and hotkeys is very thorough and interesting. I suspect it will be a great resource for others.

If you discover things during your project that you think would be a high priority for inclusion in AutoHotkey, please feel free to mention them.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
I significantly enhanced the post modifier script facilitating fast typing special characters, like umlauts or mathematical symbols or Greek letters. It has now a GUI and a tray menu for selecting replacement types for every window separately, defaults and replacement rings in a .ini file, changing icons showing the current settings, etc.

The description of the project and the SW design is in Word and in pdf format. The compiled Windows executable is SKey.exe. They need also the configuration file: SKey.ini, and 4 icons LH.ico, AA.ico, UU.ico and XX.ico, which have to be copied to the same directory as the program or the script. After started the program remains resident in memory and provides the key replacement functions assigned to HotKeys "[" and "]", until closed through its Tray icon or Windows shuts down. Installation consists of copying all the files in the same directory and installing the Humer1 keyboard layout.

The sample replacement rings are for German, Hungarian and Greek letters, mathematical and technical symbols. For other languages the .ini file has to be edited as described in the documentation.

HUMER1 keyboard layout for all Latin-Greek-Cyrillic-Symbol Unicode characters

A Unicode character table, the description of the project and the keyboard layout design is in this document. 32 Dead Keys are defined, each modifying any of the standard 94 subsequent keys of US keyboards (ignoring SPACE, and the Decimal point). These are enough for all non Asian Unicode characters, like accented Latin, Greek, Russian letters, Math symbols, diacritical marks, etc. There are 2939 such characters above the ANSI code 0xC0.

Opening the install file (e.g. with double click) installs the layout and the corresponding dll, which has to be in the i386 subdirectory of the directory where the installation file is executed from. The new keyboard layout can be used after adding it to the Installed Services under Control Panel/Keyboard/Input Locales/Change: Add "Unicodes on US keyboard".

fsmart
  • Guests
  • Last active:
  • Joined: --
I spent about 1/2 an hour trying to make this work but neither the executable humell which is uninstallable or the skey are working the way I need them to.

skey, I can't figure out how to get it to modify characters. I was able to pop up the help message box but it doesn't seem to respond the way I would expect it to.

also the icons that the links are supposed to be targeting. only one of them exists.

this looks like it could be really awesome but I don't think it is working for me in its current form at all. I might just end up rewriting a working version if an update is not posted.

thanks for the great idea.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
This script is almost 5 years old. In the mean time AHK evolved, introduced many features braking old scripts. Since there was no interest for such a long time, I stopped maintaining the code. I now use a clipboard-based approach, which is slower, but does not need installation of dll-s. The icons, the script and the ini file are in this archive.

  • Guests
  • Last active:
  • Joined: --
Hi Laszlo,

Do you also type Hungarian characters now and then? You mentioned Hungarian and your name suggests you are at least partly one. :)

Anyway, my idea is not Hungarian-specific, it applies other languages as well.

Currently, I'm switching often between Hungarian (for Hungarian text) and English layouts (for programming, mostly) and it's quite cumbersome. I also find it cumbersome to modify only single characters, because when I'm typing in Hungarian is much easier to switch layout, due to the large number of Hun chars need to be typed.

I was wondering if it was possible to make an automatic switcher which detects which language you type (e.g. í is on ` when using the Hungarian layout and ` usually don't make sense in the context, e.g. Word), switches to the proper layout automatically, and fixes the several last characters which were typed with the incorrect layout.


So it's an idea for a different script. I write it here, because you may like the idea.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
In SKey there are three mechanisms for entering special characters:

1. Post-modifiers: at pressing hotkeys (specified in the SKey.ini file), the character left to the insertion point is replaced with one of several special (Unicode) characters, in a cycle. These cycles depend on the Unicode capability of the window, which can be overridden from the tray menu.

2. A series of prefix keys (“;” or “\” etc.) modifies the character typed after them, like “;;a” -> “á”, or “\>” -> “≥”.

3. In ScrollLock mode the number keys on the top row of the keyboard are remapped. The included SKey.ini file specifies the characters, which are set to the Hungarian diacritical letters and the German sharp s (ßíäáéúüűóöő).

When I have to write a lot in Hungarian or German, I use the ScrollLock. It is the fastest, but limited to 10 special characters, and their shifted versions. For short emails or for math I use the post modifiers. For few special chars in long texts the prefix method is sufficient, but it depends on your taste and style.

I tried auto-detecting the language. It is more trouble than it is worth. E.g. in the References section of an English paper you might need to type “Pál Erdős” as an author, but you don’t want to change the keyboard layout. Not even for the containing sentence.

With AHK, as demonstrated in SKey, you can set different keyboard layouts for different windows. It can also drive you crazy: you cannot type fast if you have to concentrate on the layout at switching tasks.

In discussions with family and friends it turned out that there is no best method for typing special characters. Every one of them customized the ini file to his or her needs. E.g. some like CapsLock for post modifier, others (who don’t program) prefer “[” and “]”. - And yes, I am Hungarian.

  • Guests
  • Last active:
  • Joined: --

I tried auto-detecting the language. It is more trouble than it is worth. E.g. in the References section of an English paper you might need to type “Pál Erdős” as an author, but you don’t want to change the keyboard layout. Not even for the containing sentence.


But it happens less often that you need to type a Hungarian name in an English text. It's much more often that you want to type in Hungarian and you forgot to change the layout. At least in my case it happens often.

Post modifiers can be a good idea to fix it, but it should be extended to more than one characters, because one usually notices one is in the wrong layout only after one typed a few characters.

So for example, if I type

ban'nh;j

instead of banánhéj, do you think your script could be extended, so the user can press a hotkey and it goes back and fix the wrong characters automatically? it would be very useful, because currently one has to do it manually which is very annoying.


And yes, I am Hungarian.


Akkor akár beszélhetnénk édes anyanyelvünkön is, de a többiek kedvéért maradjunk inkább az angolnál, mert akkor mások is hozzá tudnak szólni. :D

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005

it should be extended to more than one characters, because one usually notices one is in the wrong layout only after one typed a few characters.

It is an easy task, independent of the SKey functionality. E.g. in many programs Ctrl-Shift-Left selects the previous word. Add another modifier (Win or Alt) to define a new hotkey, copy the left-word to clipboard, replace the remapped characters, paste.

John_LeBlanc
  • Members
  • 13 posts
  • Last active: Oct 14 2015 07:31 PM
  • Joined: 28 Mar 2010
I realize you're not supporting this anymore because of lack of interest but I suspect that this is because people don't know it exists. It is the best approach to inserting letters with diacritical marks that I have seen. I work in French and occasionally with transliterated Persian & Arabic.

Could I ask for two things?
1. Post the skey.ahk script so that the code can be modified (your skey.zip doesn't include that)
2. Explain how to get CapsLock back. For some reason when I run the script, I lose capslock functionality. I have tried setting my skey.ini script to avoid sole use of the capslock key so it could be used for its native function:

[HotKeys]
ForwardKey = CapsLock & Tab
BackwardKey = CapsLock & RShift
SymbolUpKey = CapsLock & Tab
SymbolDnKey = CapsLock & q
ReplaceKey = CapsLock & p
GuiWindKey = !CapsLock

This didn't work so I tried eliminating it altogether.

[HotKeys]
ForwardKey = LShift & Tab
BackwardKey = LShift & RShift
SymbolUpKey = RShift & Tab
SymbolDnKey = RShift & q
ReplaceKey = RShift & p
GuiWindKey = !RShift

Does the skey.exe file need to be recompiled in order to give me capslock functionality?

thanks for any help you can provide.


Regards, John LeBlanc
_________________________________________________________

John C. LeBlanc, MD, MSc, FRCPC
Associate Professor
Pediatrics, Psychiatry, Community Health and Epidemiology
Dalhousie University

IWK Health Centre Work phone: 902 470-8930
5850 University Avenue Work fax: 888 994-6773
Halifax, Nova Scotia Email: [email protected]
B3K 6R8 CANADA Pager: 902 470-8888
_________________________________________________________


Better mental health for Nova Scotians -- http://oneinfive.ca/