Copy cells from CSV and Pasting into chrome

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rolo6464
Posts: 23
Joined: 13 Apr 2021, 17:57

Re: Copy cells from CSV and Pasting into chrome

23 Jun 2021, 22:07

gregster wrote:
23 Jun 2021, 21:49
I pasted that exactly and I got " the following variable name contains an illegal character: "coord[A-Index].1"
Your reported (and similar) error above shows a hyphen as part of a variable name coord[A-Index].1 which I can't see anywhere in mikeyww's code.
- versus _


But I don't see why you would get that error for this code.
Which AHK version are you running ?

Code: Select all

msgbox % A_AHKversion
that was just a typo, real code i used is above, uses underscore
gregster
Posts: 8990
Joined: 30 Sep 2013, 06:48

Re: Copy cells from CSV and Pasting into chrome

23 Jun 2021, 22:10

version 1.0.48.05
That's what I thought - from September 2009. A bit outdated, don't you think?
That version doesn't support arrays, and lots of other things.
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: Copy cells from CSV and Pasting into chrome

24 Jun 2021, 06:24

Thanks to gregster for the sleuthing! I do not track which versions do what, but of course, without arrays, um, it's a no go!

Would do two things here. First, add a WinActivate.

Code: Select all

coord := [[384, 254], [145, 254]]
WinActivate, ahk_exe chrome.exe
Loop, Read, %A_ScriptDir%\test.csv
 Loop, Parse, A_LoopReadLine, CSV
 { MouseClick,, coord[A_Index].1, coord[A_Index].2
   Send %A_LoopField%
 }
Second, would upgrade your AHK. Mine is version 1.1.33.09. I would also just copy and paste this script so that you do not have differences in your testing (perhaps you already did that earlier).

Another thing to do in your testing: remove the loops, so that you can just read and process one date. Below is one way to do it. The second Return simply ends the routine after the first send. That could help you troubleshoot.

Code: Select all

coord := [[384, 254], [145, 254]]
If !WinExist("ahk_exe chrome.exe") {
 MsgBox, 48, Chrome, The Chrome window was not found.
 Return
} Else WinActivate
Loop, Read, %A_ScriptDir%\test.csv
 Loop, Parse, A_LoopReadLine, CSV
 { MouseClick,, coord[A_Index].1, coord[A_Index].2
   Send %A_LoopField%
   Return
 }
rolo6464
Posts: 23
Joined: 13 Apr 2021, 17:57

Re: Copy cells from CSV and Pasting into chrome

24 Jun 2021, 10:05

My apologies! it turns out it was my version that caused all the issues. Sorry for wasting everyones time going aback and forth, i feel embarrassed. Anyway so I updated it and it runs however I do need a slight tweak as my set of procedures has to run after the 2 coordinate mousclicks.

In other words it has to do this:

1. Click on coordinate 1
2. click on coordinate 2
3. run the procedure i listed below
4. repeat loop

right now its doing this

1. click on coordinate 1
2. running set of procedures
3. click on coordinate 2
4. running set of procedures
5. click on coordinate 1
6. running set of procedures... and so on


on the code below how do i make it so it runs the first 2 coordinate mouseclick steps then run first then run the set of procedures?

Code: Select all

coord := [[237, 684], [408, 684]]
Loop, Read, C:\1.Business\test.csv
 Loop, Parse, A_LoopReadLine, CSV
 { MouseClick,, coord[A_Index].1, coord[A_Index].2,

sleep, 1000
   Send %A_LoopField%

sleep, 1000   ; begin running procedure
MouseClick, left, 925, 281 
sleep, 10000
MouseClick, left, 351, 285 
sleep, 500
MouseClick, left, 351, 313
sleep, 1000
MouseClick, left, 1053, 449
sleep, 10000
send {enter}
sleep, 2000
MouseClick, left, 38, 251   ; end procedures


 }
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: Copy cells from CSV and Pasting into chrome

24 Jun 2021, 10:54

No worries.

It looks like you answered your own question here. Did it work?
rolo6464
Posts: 23
Joined: 13 Apr 2021, 17:57

Re: Copy cells from CSV and Pasting into chrome

24 Jun 2021, 14:14

Not sure if I did?

I can't get the code to do this part:

1. Click on coordinate 1
2. click on coordinate 2
3. run the series of steps I listed above
4. repeat loop
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: Copy cells from CSV and Pasting into chrome

24 Jun 2021, 14:38

The following worked here.

Code: Select all

coord := [[237, 684], [408, 684]]
If !WinExist("ahk_exe chrome.exe") {
 MsgBox, 48, Chrome, The Chrome window was not found.
 Return
} Else WinActivate
Loop, Read, C:\1.Business\test.csv
 Loop, Parse, A_LoopReadLine, CSV
 { MsgBox, 64, Column = %A_Index%, % "(" coord[A_Index].1 "," coord[A_Index].2 "): " A_LoopField
   MouseClick,, coord[A_Index].1, coord[A_Index].2
   Sleep, 100
   Send %A_LoopField%
   Sleep, 100
   Click, 925 281
   Send {Enter}
 }
MsgBox, 64, Done, Done!
rolo6464
Posts: 23
Joined: 13 Apr 2021, 17:57

Re: Copy cells from CSV and Pasting into chrome

24 Jun 2021, 21:22

I tried the above code but same issue, also don't get why there are message boxes now. i can't remove them because I have no idea what's needed and what is only for the msg box.

The coordinates mouse clicks are executing in the right spots, but what isn't working is that its not in the right sequence.

sequence should be:

1. Mouselclick at coordinate 1 and insert column A text
2. wait 1 second
3. Mouseclick at coordinate 2 and insert column B text
4. Wait 1 second and do a bunch of other steps
5. repeat loop
rolo6464
Posts: 23
Joined: 13 Apr 2021, 17:57

Re: Copy cells from CSV and Pasting into chrome

24 Jun 2021, 21:37

So I was able to remove the msg boxes and tested it thoroughly and its still doing the same as before. It exeucting the series of steps in between the 2 coordinate steps no after.

to illustrate what its doing:

1. Click on coordinates 1 and paste text
2. series of steps i mentioned
3. click on coordinates 2 and paste text
4.repeat loop

while i'm trying to get it to do this:

1. Click on coordinates 1 and paste text
2. wait 1 second
3. click on coordinates 2 and paste text
4. series of steps i mentioned
5.repeat loop
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: Copy cells from CSV and Pasting into chrome

24 Jun 2021, 21:50

It's just a demo. You just change the stuff inside the braces to your own routine for each iteration. Perhaps the following:

Code: Select all

coord := [[237, 684], [408, 684]]
If !WinExist("ahk_exe chrome.exe") {
 MsgBox, 48, Chrome, The Chrome window was not found.
 Return
} Else WinActivate
Loop, Read, C:\1.Business\test.csv
 Loop, Parse, A_LoopReadLine, CSV
 { MouseClick,, coord[A_Index].1, coord[A_Index].2
   Send %A_LoopField%
   If (A_Index = 2) {
    Click, 925 281
    Sleep, 10000
    Click, 351 285
    Sleep, 500
    Click, 351 313
    Sleep, 1000
    Click, 1053 449
    Sleep, 10000
    Send {Enter}
    Sleep, 2000
    Click, 38 251
   } Else Sleep, 1000
 }
MsgBox, 64, Done, Done!
rolo6464
Posts: 23
Joined: 13 Apr 2021, 17:57

Re: Copy cells from CSV and Pasting into chrome

24 Jun 2021, 22:01

mikeyww wrote:
24 Jun 2021, 21:50
It's just a demo. You just change the stuff inside the braces to your own routine for each iteration. Perhaps the following:

Code: Select all

coord := [[237, 684], [408, 684]]
If !WinExist("ahk_exe chrome.exe") {
 MsgBox, 48, Chrome, The Chrome window was not found.
 Return
} Else WinActivate
Loop, Read, C:\1.Business\test.csv
 Loop, Parse, A_LoopReadLine, CSV
 { MouseClick,, coord[A_Index].1, coord[A_Index].2
   Send %A_LoopField%
   If (A_Index = 2) {
    Click, 925 281
    Sleep, 10000
    Click, 351 285
    Sleep, 500
    Click, 351 313
    Sleep, 1000
    Click, 1053 449
    Sleep, 10000
    Send {Enter}
    Sleep, 2000
    Click, 38 251
   } Else Sleep, 1000
 }
MsgBox, 64, Done, Done!

Thank you so much that actually works, sorry for bothering you for so long, man I spent hours on trying to solve what seems so trivial yet by far most complicated authotkey script ive ever done, at least i levelled up a bit. Thanks again!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doanmvu, mikeyww and 265 guests