I am trying to make two hyphens trigger a short dash, and three hyphens trigger a long dash; like
:*?:---=::—
:*?:--=::–
except working. Here i
Click Save as
, and change the encoding scheme as shown below:
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.
The .ahk text file needed to be saved with UTF8-BOM encoding rather than UTF8
As pointed out in this comment, posting as an answer for more visibility.
EDIT: don't bother reading my answer, follow Udo Klein instruction, it's much easier and it works as it should.
how to send unicode characters using the last autohotkey version? (no need of previous unicode-compatible version to work)
Quite hard to find clear information. So to makes it clear for the beginners (like me):
Code A:
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)}
Code B:
!+^D:: ; when press CTRL+ALT+SHIFT will output "≠"
{
SendUnicodeChar(0x2260)
}
return
(watch the space!)
Improvement needed:
somehow this script doesn't work for all the unicode given by this website http://unicode-table.com/ , but someone will maybe be kind enough to tell us why some unicode are working and other don't, and maybe how to make it work for any unicode characters of this website. This one for instance http://unicode-table.com/en/0609/ doesn't work. Any idea why?