2018/11/17

181117 AutoHotkeyで特殊文字入力

AutoHotkeyで特殊文字を挿入するスクリプトを書きました。
ChangeKeyでCapsLockをF24に変更し、F24 + i キーで文字入力のダイアログが出てきます。ギリシャ文字は英語で alpha を入力すると α に、Delta を入力すると Δ が出力されます。その他、 u で μ 、d で ° などに変換し、 h を入力するとヘルプが表示されます(ヘルプというか忘備録は自分で書く必要あり)。
下記で追加可能で、出力文字は文字コード表(charmap.exe)のステータスバーにあるコードで指定できます。

If charstr = <入力>
Send {出力文字}

SendRawで文章も出力可能ですが、改行は`nで指定するなど、バッククオートでエスケープする必要があります。メールの署名の日本語・英語の切替えはMacのメールアプリだと簡単ですがThunderbirdだと面倒なので、sig で署名を呼び出せるようにしました(sj で日本語署名、se で英語署名など登録)。
入力モードが全角になっていると、区切りのハイフンなども全角になってしまうので、最初の6行でIMEの入力モードを取得して半角英数にしています。
IME.ahkライブラリを使用せずに入力モードを取得する方法は下記を参考にしました。
https://qiita.com/neokix/items/83ac2ac8e1dd405528b0


F24 & i::
WinGet, vcurrentwindow, ID, A
vimestate := DllCall("user32.dll\SendMessageA", "UInt", DllCall("imm32.dll\ImmGetDefaultIMEWnd", "Uint", vcurrentwindow), "UInt", 0x0283, "Int", 0x0005, "Int", 0)
If (vimestate=0) {
} Else {
Send, {vkf3}
}
StringCaseSense, On
InputBox, charstr, Special character insertion, Enter key strings or "h" for help, , 240, 130
If ErrorLevel = 0
If charstr = -
Send {U+2212} ; − minus
If charstr = dash
Send {U+2014} ; — Em dash
If charstr = d
Send {U+00B0} ; ° degree
If charstr = u
Send {U+00B5} ; µ micro
If charstr = micro
Send {U+00B5} ; µ micro
If charstr = ^2
Send {U+00B2} ; ² superscript two
If charstr = ^3
Send {U+00B3} ; ³ superscript three
If charstr = +-
Send {U+00B1} ; ± plus-minus
If charstr = x
Send {U+00D7} ; × Multiplication sign
If charstr = `<
Send {U+2266} ; ≦ Less-than over equal to
If charstr = `>
Send {U+2267} ; ≧ greater-than over equal to
If charstr = `=
Send {U+2252} ; ≒ Approximately equal
If charstr = root
Send {U+221A} ; √ Root
If charstr = alpha
Send {U+03B1} ; α alpha
If charstr = Alpha
Send {U+0391} ; Α Alpha
If charstr = beta
Send {U+03B2} ; β beta
If charstr = Bata
Send {U+0392} ; Β Beta
If charstr = gamma
Send {U+03B3} ; γ gamma
If charstr = Gamma
Send {U+0393} ; Γ Gamma
If charstr = delta
Send {U+03B4} ; δ delta
If charstr = Delta
Send {U+0394} ; Δ Delta
If charstr = epsilon
Send {U+03B5} ; ε epsilon
If charstr = Epsilon
Send {U+0395} ; Ε Epsilon
If charstr = zeta
Send {U+03B6} ; ζ zeta
If charstr = Zeta
Send {U+0396} ; Ζ Zeta
If charstr = eta
Send {U+03B7} ; η eta
If charstr = Eta
Send {U+0397} ; Η Eta
If charstr = theta
Send {U+03B8} ; θ theta
If charstr = Theta
Send {U+0398} ; Θ Theta
If charstr = iota
Send {U+03B9} ; ι iota
If charstr = Iota
Send {U+0399} ; Ι Iota
If charstr = kappa
Send {U+03BA} ; κ kappa
If charstr = Kappa
Send {U+039A} ; Κ Kappa
If charstr = lambda
Send {U+03BB} ; λ lambda
If charstr = Lambda
Send {U+039B} ; Λ Lambda
If charstr = mu
Send {U+03BC} ; μ mu
If charstr = Mu
Send {U+039C} ; Μ Mu
If charstr = nu
Send {U+03BD} ; ν nu
If charstr = Nu
Send {U+039D} ; Ν Nu
If charstr = xi
Send {U+03BE} ; ξ xi
If charstr = Xi
Send {U+039E} ; Ξ Xi
If charstr = omicron
Send {U+03BF} ; ο omicron
If charstr = Omicron
Send {U+039F} ; Ο Omicron
If charstr = pi
Send {U+03C0} ; π pi
If charstr = Pi
Send {U+03A0} ; Π Pi
If charstr = rho
Send {U+03C1} ; ρ rho
If charstr = Rho
Send {U+03A1} ; Ρ Rho
If charstr = sigma
Send {U+03C3} ; σ sigma
If charstr = Sigma
Send {U+03A3} ; Σ Sigma
If charstr = tau
Send {U+03C4} ; τ tau
If charstr = Tau
Send {U+03A4} ; Τ Tau
If charstr = upsilon
Send {U+03C5} ; υ upsilon
If charstr = Upsilon
Send {U+03A5} ; Υ Upsilon
If charstr = phi
Send {U+03C6} ; φ phi
If charstr = Phi
Send {U+03A6} ; Φ Phi
If charstr = chi
Send {U+03C7} ; χ chi
If charstr = Chi
Send {U+03A7} ; Χ Chi
If charstr = psi
Send {U+03C8} ; ψ psi
If charstr = Psi
Send {U+03A8} ; Ψ Psi
If charstr = omega
Send {U+03C9} ; ω omega
If charstr = Omega
Send {U+03A9} ; Ω Omega
If charstr = h
MsgBox, Special character help ("h")`n`nSpecial characters:`nμ`t"u" or "micro"`n−`t"-" (hyphen)`n—`t"dash"`n°`t"d"`n²`t^2`n³`t^3`n±`t"+-"`n×`t"x"`n≦`t"<"`n≒`t"="`n`nGreek letters (Case-sensitive):`nα`talpha`nΔ`tDelta`n
If charstr = sig
SendRaw, --------------------------------------------------`n名前`n所属`n所属`n所属`n〒住所`nTel: `nFax: `nMail: `n--------------------------------------------------`n
Return
StringCaseSense, Off ; Restore default

0 件のコメント:

コメントを投稿