how to get a working powershell command working in AHK v2 ?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Albert Schenning
Posts: 23
Joined: 03 Jan 2022, 14:40

how to get a working powershell command working in AHK v2 ?

Post by Albert Schenning » 09 Aug 2022, 07:41

Any idea how to get the following Capture2Text_CLI instruction working

in the powershell prompt this works
C:\Capture2Text\Capture2Text_CLI.exe --screen-rect "1000 335 1130 350" --whitelist "0123456789"
it gives the correct result : 736927

But how to run this command in AHK v2 ?
i tried :
Run "(C:\Capture2Text\Capture2Text_CLI.exe --screen-rect "1000 335 1130 350" --whitelist "0123456789")"

but this gives the following error in Visual studio Code:
[Running] "C:\Program Files\Autohotkey\AutoHotkey.exe" /ErrorStdOut=utf-8 "c:\Users\alber\OneDrive\Documents\Autohotkey\Untitled-1.ahk"
[Error] C:\Users\alber\OneDrive\Documents\Autohotkey\Untitled-1.ahk (4) : ==> Missing space or operator before this.
Specifically: 1000 335 1130 350" --whitelist "0123456789")")
Attachments
Screenshot 2022-08-09 143811.png
Screenshot 2022-08-09 143811.png (239 KiB) Viewed 2675 times
Last edited by gregster on 09 Aug 2022, 07:44, edited 1 time in total.
Reason: Topic moved from 'Scripts and Functions'.

User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: how to get a working powershell command working in AHK v2 ?

Post by boiler » 09 Aug 2022, 07:50

In v2, you can use single quotes to mark the beginning and end of the literal string and double quotes inside of it:

Code: Select all

Run '(C:\Capture2Text\Capture2Text_CLI.exe --screen-rect "1000 335 1130 350" --whitelist "0123456789")'
(Moved topic to v2 section of "Ask For Help")

User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: how to get a working powershell command working in AHK v2 ?

Post by kczx3 » 09 Aug 2022, 07:52

Why the parenthesis?

User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: how to get a working powershell command working in AHK v2 ?

Post by boiler » 09 Aug 2022, 07:56

I was wondering the same. Just fixed the syntax issue. The parentheses are probably a misplaced attempt at adding the optional parentheses for the Run function.

Albert Schenning
Posts: 23
Joined: 03 Jan 2022, 14:40

Re: how to get a working powershell command working in AHK v2 ?

Post by Albert Schenning » 09 Aug 2022, 08:01

Run '(C:\Capture2Text\Capture2Text_CLI.exe --screen-rect "1000 335 1130 350" --whitelist "0123456789")'

not working, see screenshot

Error: Failed attempt to launch program or document
Attachments
Screenshot 2022-08-09 145939.png
Screenshot 2022-08-09 145939.png (18.14 KiB) Viewed 2646 times

User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: how to get a working powershell command working in AHK v2 ?

Post by boiler » 09 Aug 2022, 11:17

Yes, did you see the comments about the parentheses not belonging? I previously was just pointing out how to handle the quotation marks issue without really looking at what you trying to do inside of them.

You also need to remove the parentheses or at least implement them correctly if you meant to include a function's optional parentheses. So it's either:

Code: Select all

Run 'C:\Capture2Text\Capture2Text_CLI.exe --screen-rect "1000 335 1130 350" --whitelist "0123456789"'
or:

Code: Select all

Run('C:\Capture2Text\Capture2Text_CLI.exe --screen-rect "1000 335 1130 350" --whitelist "0123456789"')

Albert Schenning
Posts: 23
Joined: 03 Jan 2022, 14:40

Re: how to get a working powershell command working in AHK v2 ?

Post by Albert Schenning » 09 Aug 2022, 12:19

i have enlarged the rectangle to search but still no results.
The following script still keeps returning an empty clipboard,so both statements don`t fill the clipboard. The powershell command :
C:\Capture2Text\Capture2Text_CLI.exe --screen-rect "1 1 1130 900" --whitelist "0123456789" returns lots of numbers.

Code: Select all

#Requires AutoHotkey v2.0-beta.1
sleep 3000
A_Clipboard := ""
Run 'C:\Capture2Text\Capture2Text_CLI.exe --screen-rect "1 1 1130 900" --whitelist "0123456789"'
msgbox A_Clipboard
sleep 3000
Run('C:\Capture2Text\Capture2Text_CLI.exe --screen-rect "1 1 1130 900" --whitelist "0123456789"')
msgbox A_Clipboard
[Mod edit: [code][/code] tags added.]

Albert Schenning
Posts: 23
Joined: 03 Jan 2022, 14:40

Re: how to get a working powershell command working in AHK v2 ?

Post by Albert Schenning » 09 Aug 2022, 12:24

solved !! This worked

Code: Select all

#Requires AutoHotkey v2.0-beta.1
sleep 3000
A_Clipboard := ""
Run('C:\Capture2Text\Capture2Text_CLI.exe --screen-rect "1 1 1130 900" --whitelist "0123456789" --clipboard')
sleep 3000
msgbox A_Clipboard
[Mod edit: [code][/code] tags added.]


Albert Schenning
Posts: 23
Joined: 03 Jan 2022, 14:40

Re: how to get a working powershell command working in AHK v2 ?

Post by Albert Schenning » 09 Aug 2022, 14:29

damm, i get numbers that i can´t explain so still not working correctly.

User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: how to get a working powershell command working in AHK v2 ?

Post by boiler » 09 Aug 2022, 15:55

Sounds just like the nature of OCR. Sometimes changing some of Capture2Text's settings can make a big difference. Whitelist is a big one, but you're already doing that. If you haven't whitelisted things like the decimal point (dot), then it won't find those and will try to force fit something else.

Albert Schenning
Posts: 23
Joined: 03 Jan 2022, 14:40

Re: how to get a working powershell command working in AHK v2 ?

Post by Albert Schenning » 09 Aug 2022, 22:29

If it was only for a few characters that went strange i would try on but it just produces totally rubbish. One realy can´t explain how even the --screen -rect should look like. I tried all kind of numbers for the coordinates and even there i see not much logic. So i stopped, after a few hours experimenting, trying to get this working. Any suggestions for other OCR solutions combined with AHK v2 ?

User avatar
boiler
Posts: 16931
Joined: 21 Dec 2014, 02:44

Re: how to get a working powershell command working in AHK v2 ?

Post by boiler » 09 Aug 2022, 22:41

I haven't done any OCR with v2, so I can't say. But in v1, I found other OCR libraries to be more reliable than Capture2Text.

Post Reply

Return to “Ask for Help (v2)”