Skip to content

Instantly share code, notes, and snippets.

@dxrcy
Last active June 13, 2022 01:34
Show Gist options
  • Save dxrcy/188b155509c08d3f45275c05610ed886 to your computer and use it in GitHub Desktop.
Save dxrcy/188b155509c08d3f45275c05610ed886 to your computer and use it in GitHub Desktop.
Convert IPA Characters with CTRL+Insert
; List of many IPA characters
allChars := ["aɑæɐ", "bβɓʙᵝ", "cçɕ", "dðɖɗ", "eəɚɵɘᵊ", "3ɛɜɝɞ", "fʩ", "gɠɢʛɡ", "hħɦɥɧʜʰʱ", "iɪɨ", "jʝɟʄʲ", "lɫɭɬʟɮʪʫꞎˡ", "mɱ", "nŋɲɳɴⁿ", "oɔœɒɶø", "pɸ", "rɾɹʁʀɻɽɺʳʶ", "sʃʂ", "tθʈᵗ", "uʊʉ", "vʌʋⱱ", "wɯʍɰʬʷ", "xχ", "yɣʎʏɤˠ", "zʒʐʑ", "?ʔʕʡʢˤˀ", "|ǀǁǃǂ", "0ʘ", "'ˈˌʼ", ">→←↘↗↓↑͢ꜜꜛ▲", "(͡", ")͜", "=⁼", "/˩˨˧˦˥", ".·", "[ʭ", "8ↀ", "*̆̚", "~̃", ":ː̈", ",̩̯"]
; CTRL+Insert
^Insert::
; Copy character
prevClipboard := Clipboard ; Save clipboard
Clipboard := ; Clear clipboard
SendInput {ShiftDown}{Left}{ShiftUp}^c{Right} ; Copy previous character
ClipWait ; Wait for clipboard to register
original := Clipboard ; Save recent clipboard string
Clipboard := prevClipboard ; Restore clipboard
; Get last character of string
hex := str2hex(original) ; Convert original to hex
lastHex := hex
hex := StrSplit(hex, " ")
For i, Code in hex { ; Check for last combining character
If (Code = "cc") {
lastHex := ""
} Else If (lastHex = "") {
lastHex = cc %Code%
}
}
original := hex2str(lastHex) ; Last character
; Get next character in list, send
For i, chars in allChars { ; Search Array for current character
Array := StrSplit(chars, "")
For j, char in Array {
If (char = original) { ; Check if correct
new := Array[j + 1] ; Set new character
If (new = "") { ; Loop back to start if end of character list
new := Array[1]
}
If (StrLen(new) = 1) { ; Stop multiple characters pasting
Send {BackSpace}%new% ; Add character
}
Return
}
}
}
Return
; Convert string to hex code (To get last combining character)
str2hex(string)
{
VarSetCapacity(bin, StrPut(string, "UTF-8")) && len := StrPut(string, &bin, "UTF-8") - 1
if !(DllCall("crypt32\CryptBinaryToString", "ptr", &bin, "uint", len, "uint", 0x4, "ptr", 0, "uint*", size))
throw Exception("CryptBinaryToString failed", -1)
VarSetCapacity(buf, size << 1, 0)
if !(DllCall("crypt32\CryptBinaryToString", "ptr", &bin, "uint", len, "uint", 0x4, "ptr", &buf, "uint*", size))
throw Exception("CryptBinaryToString failed", -1)
return StrGet(&buf)
}
; Convert hex code back to string
hex2str(string)
{
if !(DllCall("crypt32\CryptStringToBinary", "ptr", &string, "uint", 0, "uint", 0x4, "ptr", 0, "uint*", size, "ptr", 0, "ptr", 0))
throw Exception("CryptStringToBinary failed", -1)
VarSetCapacity(buf, size, 0)
if !(DllCall("crypt32\CryptStringToBinary", "ptr", &string, "uint", 0, "uint", 0x4, "ptr", &buf, "uint*", size, "ptr", 0, "ptr", 0))
throw Exception("CryptStringToBinary failed", -1)
return StrGet(&buf, size, "UTF-8")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment