Creating Listings From Clipboard

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
PercyPierce
Posts: 9
Joined: 31 Mar 2017, 22:52

Creating Listings From Clipboard

15 Feb 2018, 20:24

Hi Guys! How was your Valentines Day!

I am trying to create a script where autohotkey searches for a certain text, and then pastes text that comes following the last letter of what was found.

Here's an example:

Section: 213
Row: 13
Seat: 9-12
Confirmation Number: 70-30642/NY1
Order Summary: $755.00

Ok. Now here's my code so far:

Code: Select all

#persistent

Haystack := clipboard ; I copy that whole example above into the clipboard
Needle1 = InStr(Haystack, SEC, False, 3)
Needle2 = InStr(Haystack, ROW, False, 3)
Needle3 = InStr(Haystack, SEAT, False, 3)
Needle4 = InStr(Haystack, Confirmation Number, False, 3)
Needle5 = InStr(Haystack, Order Summary, False, 3)


^b:: ;paste the specified words that were found in the clipboard
If InStr(Haystack, Needle1)
  SendInput, %Needle1% ;I want the program to paste "213"
  SendInput, %Needle2%  ;I want the program to paste "13"
   SendInput, %Needle3%  ;I want the program to paste "9-12"
    SendInput, %Needle4%  ;I want the program to paste "70-30642/NY1"
     SendInput, %Needle5% ;I want the program to paste "$755.00"
return

Now my problem with this code is that it keeps pasting the position of the string instead of the WORD.
How do I get ahk to paste the WORD of the found string and not the position in number format?
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Creating Listings From Clipboard

15 Feb 2018, 21:58

Note that your SEC, ROW, SEAT, Confirmation Number, Order Summary are all blank values here, because you didn't pass them as strings.

RegExMatch() has an output parameter to capture the matching needle. You can then break it up by specifying a certain portion to be captured in a pseudo-array.

(I'm going to skip making the Haystack variable; we'll just work off the clipboard)

To start you off:

Code: Select all

RegExMatch(clipboard,"Section: (\d+)",sec)
MsgBox %sec1% ; try it with "sec" only and see that the word "Section: " is included.
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Creating Listings From Clipboard

16 Feb 2018, 09:47

Code: Select all

var = 
(
Section: 213
Row: 13
Seat: 9-12
Confirmation Number: 70-30642/NY1
Order Summary: $755.00
)
loop, parse, var, `n,`r
    str .= trim(RegExReplace(A_LoopField, "m).*:\S?(.*)$","$1")) "`n"
sendinput,  % str
ExitApp
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google Adsense [Bot], Ragnar, yuu453 and 301 guests