3
votes

Because times to times, I need to translate text into different languages using special characters not present on the keyboard, like ı, ş, ñ, ğ.

I created a script with AutoHotKey, transforming the combination of ^ + ^ + s -> into ş, in the same way for the others characters.

The script is working fine, but only working if the character preceding the first ^ is a space or the first letter. For example, when typing ma^^n <- this will not transform my character, whereas ^^n <- will transform it.

Here is the script, I specify that I only learned this language when creating the script:

:*c:^^S::
SendUnicodeChar(0x015E)
Return

:*c:^^s::
SendUnicodeChar(0x015F)
Return

:*c:^^i::
SendUnicodeChar(0x131)
Return

:*c:^^I::
SendUnicodeChar(0x130)
Return

:*c:^^g::
SendUnicodeChar(0x011F)
Return

:*c:^^G::
SendUnicodeChar(0x011E)
Return

:*c:^^n::
SendUnicodeChar(0x00F1)
Return

:*c:^^N::
SendUnicodeChar(0x00D1)
Return

:*c:^^c::
SendUnicodeChar(0x00E7)
Return

:*c:^^C::
SendUnicodeChar(0x00C7)
Return

; Find the corresponding letter from the unicode
; and send the input back
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)
}  
1
Add a ? to each hotstring's options, e.g. :?*c:^^S::SendUnicodeChar(0x015E). - MCL
MCL, why not make this the official answer? - Robert Ilbrink
@MCL, you should post that as an answer so I could accept it ! This solved my problem. - FR073N
Send, {U+015E} can also be used instead of SendUnicodeChar(0x015E) - analogous for the others - Cadoiz

1 Answers

5
votes

As per the AHK docs on hotstring options:

? (question mark): The hotstring will be triggered even when it is inside another word; that is, when the character typed immediately before it is alphanumeric. For example, if :?:al::airline is a hotstring, typing "practical " would produce "practicairline ". Use ?0 to turn this option back off.

Consequentially, your hotstrings should look like this:

:?*c:^^S::
   SendUnicodeChar(0x015E)
Return

You may also want to globally set the options, so that you won't have to apply them to every hotstring individually:

#Hotstring ?*c

::^^S::
    SendUnicodeChar(0x015E)
Return

::^^s::
    SendUnicodeChar(0x015F)
Return