![AutoHotKey フォーマット時間](https://rvso.com/image/1567502/AutoHotKey%20%E3%83%95%E3%82%A9%E3%83%BC%E3%83%9E%E3%83%83%E3%83%88%E6%99%82%E9%96%93.png)
24 時間制を次のようにフォーマットしようとしています。
「1930+」と入力すると→19:30
「0630+」と入力すると→06:30
基本的に、0 から 9 までの数字の末尾に「+」が読み取られると、2 桁後ろに「:」が追加されます。これをどのように行うのかはよくわかりません。
答え1
; *: An ending character is not required
; ?: The hotstring will be triggered even when it is inside another word
#Hotstring * ?
::0+::
::1+::
; ...
::9+::
PriorKey := SubStr(A_PriorKey, 0) ; remove "Numpad" if using number pad
SendInput, %PriorKey%{Left 2}:{Right 2}
return
もっと正確に言うと:
#Hotstring * ?
::0+::
::1+::
; ...
::9+::
ClipSaved := ClipboardAll ; save Clipboard
clipboard := "" ; empty the clipboard
PriorKey := SubStr(A_PriorKey, 0) ; remove "Numpad" if using number pad
SendInput, %PriorKey%{Shift Down}{Left 4}{Shift Up} ; select the last 4 typed chars
Send, ^c ; copy the selected text
ClipWait, 1 ; wait for the clipboard to contain data.
if (!ErrorLevel) ; If NOT ErrorLevel clipwait found data on the clipboard
{
If ((clipboard is number) && (SubStr(clipboard, 1, 2) < 24) && (SubStr(clipboard, -1) < 60))
Send, {Left}{Right 2}:{Right 2}
else
Send, {Right}
}
Sleep, 300
clipboard := ClipSaved ; restore original clipboard
return