Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I declare a variable within a hotstring in AutoHotKey?

Tags:

autohotkey

I'm trying to create a script that will take a name and add it to a pre-written block of text.

Essentially, I want to write "emailDave" and have the name Dave inserted into a string of text that is then sent. I'm just not sure how to modify a hotstring this way.

I'm currently using a method that asks for the name using an InputBox and inserts the name into the text. That works just fine on the Desktop, but I'm using Windows 8 and for some horrible reason, InputBox won't show up in-App (i.e. outside of Desktop mode).

I know there's got to be a way to use the text I input "email vs emailDave" to affect the variable instead of taking me on this goose chase with InputBox.

That said, if anyone knows a workaround for displaying InputBox in Windows 8 apps (particularly Mail), that would be more than helpful.

Current script that runs fine on Desktop but won't work in-App:

::email::
InputBox, thename, Enter the name, What is the name
SendInput Hi %thename%,{enter}{enter}Sample text.{enter}{enter}Thanks,{enter}Zach
Return

Is there any way to make something like this work?

::email{%thename%}::
SendInput Hi %thename%,{enter}{enter}Sample text.{enter}{enter}Thanks,{enter}Zach
Return
like image 231
Zach G Avatar asked Nov 04 '22 02:11

Zach G


1 Answers

How about his:

:?*:email::
Input, thename, v,{Enter}{Space}
If (thename = "")
{
    SendInput, {Bs}email `
    Return
}
StringLen,MyLen, thename
MyLen++
SendInput {BackSpace %MyLen%}Hi +%thename%,{Enter 2}Sample text.{Enter 2}Thanks,{Enter}Zach
Return

By adding a + in front of the name string the first letter will be capitalized.

Input: "emailrobert{Enter}" or "emailRobert{Enter}" both give:

Hi Robert,

Sample text.

Thanks,
Zach

and email{Space} will give email{Space}.

like image 191
Robert Ilbrink Avatar answered Jan 04 '23 13:01

Robert Ilbrink