5

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
Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
Zach G
  • 53
  • 1
  • 3
  • The InputBox code works fine for me in Windows 8. Are you sure your AutoHotkey is running as Admin? This [link](http://geekswithblogs.net/deadlydog/archive/2012/09/10/autohotkey-cannot-interact-with-windows-8-windowshellipor-can-it.aspx) shows you how. – Elliot DeNolf Mar 19 '13 at 18:42
  • The InputBox code works for me as well in Desktop mode, but are you able to use the hotkey ::email:: in the Mail app without it asking you to head back to the desktop for the InputBox? I'd like the InputBox to appear on top of the Mail App (or any App, for that matter). – Zach G Mar 19 '13 at 18:47
  • Also, yes, I'm running as Admin (though I will use the tutorial you posted to make that happen automatically). – Zach G Mar 19 '13 at 18:48

3 Answers3

1

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}.

Robert Ilbrink
  • 7,738
  • 2
  • 22
  • 32
  • Thanks, but that didn't work for me. Any other options? And yes, I'm only using "email" as a sample for this forum. It's a unique string. – Zach G Mar 19 '13 at 18:56
  • For some reason, every time I try this one (in any fashion) using the ?* method, the word I type disappears immediately (like "email") and the keyboard ceases to function until I force quit AHK? Is that an issue on my end? And apologies on being vague: the script doesn't seem to function as it should. (See above) – Zach G Mar 19 '13 at 19:10
  • This is an issue on your end. Which version of AHK are you using? The word email disappears immediately and the name of the receiver is typed "blind", but AHK should "release" the keyboard as soon as you press [Enter] or [Esc]. Did you check Elliot's solution, that looks promising. – Robert Ilbrink Mar 19 '13 at 19:17
  • Robert! I should never have doubted you. I mistook the "blind" issue for a keyboard error. I have tried again and it worked exactly as you said. You're a lifesaver. Is there a way to type the word without it being "blind"? If not, it's no big deal. Just curious. This has been incredibly helpful, thanks! – Zach G Mar 19 '13 at 19:20
  • Defining a hotstring with `?` and `*` tells AHK not to worry if there’s a preceding space and not wait for an ending character (or anything else). This code will run any time you type the letters in the word “email” anywhere, as soon as you hit the `l`. – Tyler James Young Sep 09 '14 at 18:20
1

If you really would like to avoid using an InputBox, I have a more complicated solution for you. You can use a library called RegEx Powered Dynamic HotStrings.

Save the file at that link into your lib folder inside the folder containing AutoHotkey.exe (create if necessary).

In this example, you type emailJohn followed by a Space.

#Include lib\DynamicHotstrings.ahk

hotstrings("email(\w+)\s", "email")
Return

email:
    SendInput, Hi %$1%,{Enter 2}Sample text.{Enter 2}Thanks,{Enter}Zach
return
Elliot DeNolf
  • 2,920
  • 1
  • 15
  • 12
  • Thanks for the help! I'm going to avoid any external libraries just yet - I'd like to master (as best I can) the basics of AHK and go on from there. Much obliged! – Zach G Mar 19 '13 at 19:21
0
::email::
inputbox, name
msgbox, %name%
return

take "dave" out of the hotstring

After you test, replace the msgbox, %name% with whatever send line you want.   

Ooker
  • 1,969
  • 4
  • 28
  • 58
  • Your solution works perfectly in e.g. Windows 7, but Zach wrote that in Windows 8, when in he runs this "in-App" (tiles), the inputbox (or any other regular window) doesn't work. That is why we had to find a solution around this Windows 8 specific issue. – Robert Ilbrink Mar 21 '13 at 19:01