1
votes

I have a problem when using some of my AutoHotKey (AHK) scripts in combination with Emacs. The AHK scripts that gives me problems are for inserting the Norwegian special letters æ, ø, å, Æ, Ø, Å. The format of theses scripts are here exemplified with the AHK script for the letter æ:

:c?*:,e:: ;  write the letter "æ" in text editor
send, {ALTDOWN}{Numpad1}{Numpad4}{Numpad5}{ALTUP}
return

..where {ALTDOWN} and {ALTUP} are AHK's commands for, respectively, pressing down and releasing the ALT-key. In this script AHK in effect sends the ASCII number 145 to the text editor to represent the letter æ. So when I type ,e in any text editor (except Emacs) the result is the letter æ.

However this script does not function when used in the text editor Emacs. It seems to interfere with Emacs' repeating command, ALT-(n), where n is the number of times you want to repeat a command. For instance, the command ALT 50 , will repeat the , 50 times.

So, if I write ,e in my Emacs editor nothing happens, but if I type , e_ the whitespace _ after e is repeated 145 times! Similarly, if I write , et to make the letter combination æt, I get the letter t repeated 145 times. Not exactly what I want : )

How can I change my AHK so that I still can write the special letters, but not interfering with Emacs' repeating command?

1

1 Answers

2
votes

First of all, I'm pretty sure you can disable the repeating command in Emac itself.

I can't find æ (alt 145) in charmap.exe. Instead, I'll use æ (alt 0230).

Things which you could try: Instead of send, {ALTDOWN}{Numpad 0}{Numpad2}{Numpad3}{Numpad0}{ALTUP}, use

  • send, {ASC 0230}
  • send, æ (yes, this works with almost everything)
  • SendUnicodeChar(0x00E6) (00E6 can also be found in charmap)

For the latter, you'll need this function:

; SOURCE for the following: http://www.autohotkey.com/board/topic/16404-inserting-unicode-special-characters/
SendUnicodeChar(charCode)
{
    VarSetCapacity(ki, 28 * 2, 0)
    EncodeInteger(&ki + 0, 1)
    EncodeInteger(&ki + 6, charCode)
    EncodeInteger(&ki + 8, 4)
    EncodeInteger(&ki +28, 1)
    EncodeInteger(&ki +34, charCode)
    EncodeInteger(&ki +36, 4|2)

    DllCall("SendInput", "UInt", 2, "UInt", &ki, "Int", 28)
}

EncodeInteger(ref, val)
{
    DllCall("ntdll\RtlFillMemoryUlong", "Uint", ref, "Uint", 4, "Uint", val)
}

Another idea: Why not disable Alt in Emac?

#ifWinActive, Emacs
Alt::return
#ifWinActive