topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Sunday December 15, 2024, 5:14 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Sending user-supplied text  (Read 9531 times)

ralphkru

  • Participant
  • Joined in 2011
  • *
  • Posts: 5
    • View Profile
    • Donate to Member
Sending user-supplied text
« on: June 12, 2012, 01:08 AM »
Prime newby to AHK and programming of any sort.  I think this question is ground-level basic.  I would like to send text to an application (say Word), with part of the text being a value I supply.  For instance, I might want to put in an identification number of some sort off of a list of such numbers.  Real basic data entry.  I've read about AHK's Input box, but, frankly, didn't understand it very well.  Anybody explain this in easy level tech words?  Thanks. 

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Sending user-supplied text
« Reply #1 on: June 12, 2012, 04:04 PM »
To send text see the help for Send, SendRaw etc..

Also if you search here:
http://www.autohotke...849838013c5ed6a8e81d

It's probably already been answered.

ralphkru

  • Participant
  • Joined in 2011
  • *
  • Posts: 5
    • View Profile
    • Donate to Member
Re: Sending user-supplied text
« Reply #2 on: June 12, 2012, 09:39 PM »
Yeah, I'm doing that.  Don't always understand everything I'm reading.  Looking for examples in other people's scripts of how those commands are used.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Sending user-supplied text
« Reply #3 on: June 12, 2012, 09:49 PM »
AHK isn't the easiest first language. AHK_L helps somewhat. But the syntax is funky. Maybe give AutoIt a try. It's another macro language.  It has a Send() function that's similar, but the language syntax may be easier to catch onto if you are new to programming. I've been programming PCs since 1986 and AHK still throws me.

http://www.autoitscr...com/forum/index.php?

ralphkru

  • Participant
  • Joined in 2011
  • *
  • Posts: 5
    • View Profile
    • Donate to Member
Re: Sending user-supplied text
« Reply #4 on: June 12, 2012, 10:16 PM »
Good suggestion.  I did look at Autoit before I got into AHK_L.  The learning curves seemed pretty similar.  But there were some AHK scripts (real simple ones) that I could figure out just by looking at them.  That's what made me decide to try AHK.  Autoit's syntax seems a tad more formal, if that's the word I want.  I'll stick with AHK for a while longer anyway, but thanks.

Here's a question out of the command help.  For InputBox they show InputBox, OutputVar [, Title, Prompt, HIDE, Width, Height, X, Y, Font, Timeout, Default].  I assume the [ ] brackets mean the commands, I guess I mean parameters, are optional.  The question is, from the examples they show, you have to put a comma followed by a space for every one of those parameters you don't want to use.  That is, if you want to include parameter #1 and 3, but not #2, you have to put the comma+space between 1 and 3.  Correct?  And if you don't want to use any parameters after #3, you can just stop?

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,832
    • View Profile
    • Donate to Member
Re: Sending user-supplied text
« Reply #5 on: June 12, 2012, 10:27 PM »
Here's a question out of the command help.  For InputBox they show InputBox, OutputVar [, Title, Prompt, HIDE, Width, Height, X, Y, Font, Timeout, Default].  I assume the [ ] brackets mean the commands, I guess I mean parameters, are optional.  The question is, from the examples they show, you have to put a comma followed by a space for every one of those parameters you don't want to use.  That is, if you want to include parameter #1 and 3, but not #2, you have to put the comma+space between 1 and 3.  Correct?  And if you don't want to use any parameters after #3, you can just stop?

correct - so this would look like

  input box, VarName, Par#1,,Par#3


MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Sending user-supplied text
« Reply #6 on: June 12, 2012, 11:43 PM »
The best thing to do is create a script that does as close to what you want as you can get, then post it in the Support forum.  Explain what you are trying to do. Plenty of AHK programmers will offer suggestions and code snippets. The traffic will be at least an order of magnitude greater than on this thread.

http://www.autohotke...ea37362128d6bb672472

Also it's good to follow these suggestions:
http://www.autohotke...c.php?f=1&t=4986

If you are trying to do something like Close All Windows and there's a CloseAllWindows function in the help index that you didn't bother too look for, you won't get much sympathy. But if you follow the suggestions many people will try to help you out there.

As for syntax, AHK is the only programming language I'm familiar with that has a string data type that's wrapped in double quotes sometimes, but just written in at other times with no quoting whatever. It drives me nuts.  I think if they ever get to AHK2 strings will be double quoted always. Also they will dump the comma syntax. It's too primitive.

The trouble is it handles context specific hotkeys in a way that AutoIt can't. So I can't ignore it even if I'd like to. :)


« Last Edit: June 12, 2012, 11:48 PM by MilesAhead »

rjbull

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 3,205
    • View Profile
    • Donate to Member
Re: Sending user-supplied text
« Reply #7 on: June 13, 2012, 03:04 PM »
OP:  do you mean something like pasting the text of a form letter, with only the name changed?  If so, there are already ways of doing that without actually needing to write your own program.

ralphkru

  • Participant
  • Joined in 2011
  • *
  • Posts: 5
    • View Profile
    • Donate to Member
Re: Sending user-supplied text
« Reply #8 on: June 13, 2012, 11:35 PM »
Right.  I am, in fact, using a program that allows me to do that kind of thing (http://www.sector-se.../software/controlpad), but I'm really interested in trying to learn how to use AHK.  If something useful comes out of this, that would be frosting on the cake.

This program I stole straight out of the docs:
InputBox, UserInput, Phone Number, Please enter a phone number., , 640, 480
if ErrorLevel
    MsgBox, CANCEL was pressed.
else
    MsgBox, You entered "%UserInput%"
This works fine and the variable containing the user's input does half of what I want.  Instead of the 2nd Msg Box, I want to send a sentence like Your phone number is %UserInput% to Word or Notepad or some other app.  I've tried replacing the 2nd MsgBox line with a Send command.  That didn't work.  I tried assigning a hotkey to the script, so I could actually be sitting in my target app when I called the script up.  That didn't work.  I've been looking at WinActivate, but I'm not sure how to use that.  Mainly, I'm not sure if the problem is in the script (syntax) or that I'm lacking a command.

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,832
    • View Profile
    • Donate to Member
Re: Sending user-supplied text
« Reply #9 on: June 14, 2012, 12:23 AM »
This program I stole straight out of the docs:
InputBox, UserInput, Phone Number, Please enter a phone number., , 640, 480
if ErrorLevel
    MsgBox, CANCEL was pressed.
else
    MsgBox, You entered "%UserInput%"
This works fine and the variable containing the user's input does half of what I want.  Instead of the 2nd Msg Box, I want to send a sentence like Your phone number is %UserInput% to Word or Notepad or some other app.  I've tried replacing the 2nd MsgBox line with a Send command.  That didn't work.  I tried assigning a hotkey to the script, so I could actually be sitting in my target app when I called the script up.  That didn't work.  I've been looking at WinActivate, but I'm not sure how to use that.  Mainly, I'm not sure if the problem is in the script (syntax) or that I'm lacking a command.

here's a super simple example using 2 hotkeys (one for input, and one for output) -

#persistent
#singleinstance, ignore

#I::InputBox, UserInput, Enter a phone number,,, 150, 90

#O::sendinput, Your input value was '%userinput%'

WIN+I invokes the input box and populates the var UserInput with a value (or not, if you cancel the dialog)

WIN+O sends the output to wherever the cursor is (so some care may need to be taken)

Of course you can make this a lot more sophisticated depending on your requirements, but this covers the basics of what you're trying to do

ralphkru

  • Participant
  • Joined in 2011
  • *
  • Posts: 5
    • View Profile
    • Donate to Member
Re: Sending user-supplied text
« Reply #10 on: June 14, 2012, 12:49 AM »
Sendinput.  I thought I'd read everything relating to Send.  Missed that.  This looks good.  I'll test it tomorrow, when I may have more questions.  Thanks very much.