Quantcast
Channel: AutoHotkey Community
Viewing all articles
Browse latest Browse all 579

Ask for Help (v2) • Re: Dynamic Hotstrings

$
0
0
Okay, a more fun version... Type "dash," then one of the characters -+#*~+ or x, then a digit, then Space.

Another interesting thing... AHK gurus, please note the IF Else statement near the bottom. It seems like the code should work the same with or without the {braces}, yes?? But try this: If you type the trigger, then a non-digit (or digit > 199), you get the trigger typed out. For example, typing dash-hello{Space} yields "dash-hello." HOWEVER, if you comment-out the curly braces and try it, the Else is skipped (var 'output' is not set to anything). Mystery solved! See below. :lol:

CODE:

#SingleInstance
#Requires AutoHotkey v2+
; Dash maker. Experimental !!!!
; based on an inputHook from mikeyww.
esc::ExitApp

For item in ['-','=','#','*','~','+','x']
HotString(':*:dash' item, startHook.Bind())
startHook(*)
{Global thisString := ""
Global dih := inputHook('I2')
dih.OnChar := dih_OnChar
dih.OnKeyUp := dih_EndChar
dih.KeyOpt('{Space}{Enter}{Tab}', '+N') ; End keys end the capturing.
dih.Start
}

dih_OnChar(dih, char)
{GLobal thisString .= char
}

dih_EndChar(tih, vk, sc) ; Capturing has ended, so evaluate the input.
{Global thisString
output := ""
thisDash := '{' subStr(A_ThisHotkey, -1) '}' ; <--- The curley braces allow us to use # or +.
If (IsNumber(thisString) and thisString < 200) { ; if the captured input is a number and less than 200.
Loop thisString ; loop number of times.
output .= thisDash
}
Else {
output := "dash" thisDash thisString ; too long, or not a number, so just type content.
}
SendInput output
dih.Stop
thisString := ""
}

Statistics: Posted by kunkel321 — Today, 13:38



Viewing all articles
Browse latest Browse all 579

Trending Articles