我刚开始使用AutoHotkey,并且在阅读文档时,我还没有发现任何暗示可以完成此任务的建议。
我希望能够输入X-SAMPA文本并将其替换为相应的IPA。为了引发X-SAMPA,我打算将其用X[
和]
括起来。因此,如果我输入X[T@]
并按魔术键,它将被替换为/θə/
。
AHK完全可以吗?
怎么办?同样,我没有在文档中找到任何线索。 (注意:我可以找到声明魔术密钥的方法;它正在进行的“智能替换”工作并不明显。)
答案 0 :(得分:1)
; Save Script with UTF-8-Bom Encoding
xsampa := ComObjCreate("Scripting.Dictionary")
; Lower, Uppercase, Symbols, Diacritics - X-Sampa Dictionary
; - Found on https://en.wikipedia.org/wiki/X-SAMPA
xsampa.item("b_<") := "ɓ", xsampa.item("B") := "β", xsampa.item("L\") := "ʟ"
xsampa.item("d_<") := "ɗ", xsampa.item("B\") := "ʙ", xsampa.item("M") := "ɯ"
xsampa.item("g_<") := "ɠ", xsampa.item("C") := "ç", xsampa.item("M\") := "ɰ"
xsampa.item("h\") := "ɦ", xsampa.item("D") := "ð", xsampa.item("N") := "ŋ"
xsampa.item("j\") := "ʝ", xsampa.item("E") := "ɛ", xsampa.item("N\") := "ɴ"
xsampa.item("l`") := "ɭ", xsampa.item("F") := "ɱ", xsampa.item("O") := "ɔ"
xsampa.item("l\") := "ɺ", xsampa.item("G") := "ɣ", xsampa.item("O\") := "ʘ"
xsampa.item("n``") := "ɳ", xsampa.item("G\") := "ɢ", xsampa.item("P") := "ʋ"
xsampa.item("p\") := "ɸ", xsampa.item("G\_<") := "ʛ", xsampa.item("Q") := "ɒ"
xsampa.item("r``") := "ɽ", xsampa.item("H") := "ɥ", xsampa.item("R") := "ʁ"
xsampa.item("r\") := "ɹ", xsampa.item("H\") := "ʜ", xsampa.item("R\") := "ʀ"
xsampa.item("r\``") := "ɻ", xsampa.item("I") := "ɪ", xsampa.item("S") := "ʃ"
xsampa.item("s``") := "ʂ", xsampa.item("I\") := "ɪ̈", xsampa.item("T") := "θ"
xsampa.item("t``") := "ʈ", xsampa.item("J") := "ɲ", xsampa.item("U") := "ʊ"
xsampa.item("s\") := "ɕ", xsampa.item("J\") := "ɟ", xsampa.item("U\") := "ʊ̈"
xsampa.item("v\") := "ʋ", xsampa.item("J\_<") := "ʄ", xsampa.item("V") := "ʌ"
xsampa.item("x\") := "ɧ", xsampa.item("K") := "ɬ", xsampa.item("W") := "ʍ"
xsampa.item("z``") := "ʐ", xsampa.item("K\") := "ɮ", xsampa.item("X") := "χ"
xsampa.item("z\") := "ʑ", xsampa.item("L") := "ʎ", xsampa.item("X\") := "ħ"
xsampa.item("Y") := "ʏ", xsampa.item("Z") := "ʒ", xsampa.item("""") := "ˈ"
xsampa.item("%") := "ˌ", xsampa.item("'") := "ʲ", xsampa.item(":") := "ː"
xsampa.item(":\") := "ˑ", xsampa.item("-") := " ", xsampa.item("@") := "ə"
xsampa.item("@\") := "ɘ", xsampa.item("{") := "æ", xsampa.item("}") := "ʉ"
xsampa.item("1") := "ɨ", xsampa.item("2") := "ø", xsampa.item("3") := "ɜ"
xsampa.item("3\") := "ɞ", xsampa.item("4") := "ɾ", xsampa.item("5") := "ɫ"
xsampa.item("6") := "ɐ", xsampa.item("7") := "ɤ", xsampa.item("8") := "ɵ"
xsampa.item("9") := "œ", xsampa.item("&") := "ɶ", xsampa.item("?") := "ʔ"
xsampa.item("?\") := "ʕ", xsampa.item("<\") := "ʢ", xsampa.item(">\") := "ʡ"
xsampa.item("^") := "ꜛ", xsampa.item("!") := "ꜜ", xsampa.item("!\") := "ǃ"
xsampa.item("|") := "|", xsampa.item("|\") := "ǀ", xsampa.item("||") := "‖"
xsampa.item("|\|\") := "ǁ", xsampa.item("=\") := "ǂ", xsampa.item("-\") := "‿"
xsampa.item("_""") := "̈", xsampa.item("_+") := "̟", xsampa.item("_/") := "̌"
xsampa.item("_-") := "̠" , xsampa.item("_/") := "̌", xsampa.item("_0") := "̥"
xsampa.item("=") := "̩" , xsampa.item("_=") := "̩" , xsampa.item("_>") := "ʼ"
xsampa.item("_?\") := "ˤ", xsampa.item("_\") := "̂" , xsampa.item("_^") := "̯"
xsampa.item("_}") := "̚" , xsampa.item("``") := "˞" , xsampa.item("~") := "̃"
xsampa.item("_~") := "̃" , xsampa.item("_A") := "̘" , xsampa.item("_a") := "̺"
xsampa.item("_B") := "̏" , xsampa.item("_B_L") := "᷅" , xsampa.item("_c") := "̜"
xsampa.item("_d") := "̪" , xsampa.item("_e") := "̴" , xsampa.item("<F>") := "↘"
xsampa.item("_F") := "̂" , xsampa.item("_G") := "ˠ", xsampa.item("_H") := "́"
xsampa.item("_H_T") := "᷄" , xsampa.item("_h") := "ʰ", xsampa.item("_j") := "ʲ"
xsampa.item("_k") := "̰" , xsampa.item("_L") := "̀" , xsampa.item("_l") := "ˡ"
xsampa.item("_M") := "̄" , xsampa.item("_m") := "̻" , xsampa.item("_N") := "̼"
xsampa.item("_n") := "ⁿ", xsampa.item("_O") := "̹" , xsampa.item("_o") := "̞"
xsampa.item("_q") := "̙" , xsampa.item("<R>") := "↗", xsampa.item("_R") := "̌"
xsampa.item("_R_F") := "᷈" , xsampa.item("_r") := "̝" , xsampa.item("_T") := "̋"
xsampa.item("_t") := "̤" , xsampa.item("_v") := "̬" , xsampa.item("_w") := "ʷ"
xsampa.item("_X") := "̆" , xsampa.item("_x") := "̽"
:*b0:x[::
While (e != "EndKey:]"){
Input, key, v, ]{BS}{Enter}{Esc}
e := ErrorLevel
typed .= key, key := ""
If (e == "EndKey:Backspace")
typed := SubStr(typed, 1, (StrLen(typed)-1))
if (e == "EndKey:Escape" || e == "EndKey:Enter") {
SendInput % "{BackSpace " StrLen(typed)+1 "}"
newText := typed := e := ""
return
}
}
NewText := xsampaParse(xsampa, typed)
SendInput % "{BackSpace " StrLen(typed)+3 "}" newText
newText := typed := e := ""
return
xsampaParse(xsampa, typed, NewText:="", pos:=4) {
if (StrLen(typed)) {
if (xsampa.Exists(SubStr(typed, 1, pos))) {
newText .= xsampa.item(SubStr(typed, 1, pos))
typed := SubStr(typed, pos+1)
return xsampaParse(xsampa, typed, NewText)
} else if (pos == 1) {
newText .= SubStr(typed, 1, pos)
typed := SubStr(typed, pos+1)
return xsampaParse(xsampa, typed, NewText)
} else return xsampaParse(xsampa, typed, NewText, --pos)
} else Return newText
}