How do I use Unicode in AutoHotKey?

前端 未结 4 1292
盖世英雄少女心
盖世英雄少女心 2021-02-05 03:10

I am trying to make two hyphens trigger a short dash, and three hyphens trigger a long dash; like

:*?:---=::—
:*?:--=::–

except working. Here i

4条回答
  •  清酒与你
    2021-02-05 03:36

    I copied the code below from the AutoHotKey forums:

    ;IMPORTANT, you must save this script as UTF-8 to make it work.
    
    ::!?::
    ::?!::
    PutUni("‽")
    Return
    
    ::neko::
    PutUni("猫")
    Return
    
    :?:damn::
    PutUni("✩☠#‼")
    Return
    
    ;Paste UTF8 string (Hex encoded or not) as unicode.
    ;If you don't use Hex encoding, you must save your script as UTF8
    PutUni(DataIn)
    {
        SavedClip := ClipBoardAll
        ClipBoard =
        If RegExMatch(DataIn, "^[0-9a-fA-F]+$")
        {
            Loop % StrLen(DataIn) / 2
            UTF8Code .= Chr("0x" . SubStr(DataIn, A_Index * 2 - 1, 2))
        }
        Else
            UTF8Code := DataIn
    
        Transform, ClipBoard, Unicode, %UTF8Code%
        Send ^v
        Sleep 100 ;Generous, less wait or none will often work.
        ClipBoard := SavedClip
        Return
    }
    

    The PutUni function will "translate" the desired input to the desired Unicode output.

提交回复
热议问题