1

I'm trying to format 24 hour time like this.

If I type "1930+" → 19:30

If I type "0630+" → 06:30

Basically when it reads a "+" at the end of a number 0-9 then it adds a " : " two places backwards. Just not sure how to do this.

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

If you want to be more precise:

#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

https://autohotkey.com/docs/Hotstrings.htm#Options

  • Is there a way to make it work with numbers entered via the number pad? Works great but only if using number keys that are located above the letters. – Andrew Aug 8 '18 at 14:37
  • Try the edited codes. – user3419297 Aug 8 '18 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.