Copy 2 OCR data and merge into 1 Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
neasoo
Posts: 3
Joined: 05 Feb 2023, 22:52

Copy 2 OCR data and merge into 1

Post by neasoo » 05 Feb 2023, 23:00

Hi guys,

Right now I have a GUI where I press a "Copy Data" button and it will capture the on screen data, then "Paste Data" button would paste the OCR data.

I want to make it so that I can press "Copy Data" button twice, to capture 2 different on screen data. Then when "Paste Data" is pressed, the OCR data would be merged into one.
Eg: "Copy Data" captures "chicken", then I press "Copy Data" again to capture "nugget". Paste data will return "chicken nugget".

Been scratching my head at this for awhile, will appreciate any help I can get. Thank you!

Code: Select all

CopyData:
Gui, Submit, NoHide

BlockInput MouseMove
WinActivate, ahk_exe Mtl.exe
sleep, 500
vvdata := OCR([390, 90, 85, 630], "eng")
FormatTime, CurrentTime,, HH:mm

Clipboard := ""
Clipboard := "
(LTrim
" CurrentTime "
" vvdata "
)"

BlockInput MouseMoveOff

PasteData:
Gui, Submit, NoHide
{
	WinActivate, ahk_exe chrome.exe
	WinMaximize, chrome.exe
	Send ^v
}
Gui, Show
Return

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

Re: Copy 2 OCR data and merge into 1  Topic is solved

Post by mikeyww » 05 Feb 2023, 23:39

This demo might help.

Code: Select all

#Requires AutoHotkey v1.1.33

str := ""

F3::str := append(str, "chicken")
F4::str := append(str, "nugget")
F5::
SendInput % "{Text}" str
str := ""
Return

append(str, txt) {
 SoundBeep 1500
 Return Trim(str " " txt)
}
Or:

Code: Select all

#Requires AutoHotkey v1.1.33
str := ""
F3::str .= " chicken"
F4::str .= " nugget"
F5::
SendInput % "{Text}" Trim(str)
str := ""
Return
If you are new to AutoHotkey, you might want to try its current version (v2.x).

Code: Select all

#Requires AutoHotkey v2.0

str := ""

F3::Global str := append(str, "chicken")
F4::Global str := append(str, "nugget")
F5:: {
 Send "{Text}" str
 Global str := ""
}

append(str, txt) {
 SoundBeep 1500
 Return Trim(str " " txt)
}

neasoo
Posts: 3
Joined: 05 Feb 2023, 22:52

Re: Copy 2 OCR data and merge into 1

Post by neasoo » 06 Feb 2023, 11:25

Haven't quite figured it out yet but thank you mikeyww! Will experiment with it more :)
mikeyww wrote:
05 Feb 2023, 23:39
This demo might help.

Code: Select all

#Requires AutoHotkey v1.1.33

str := ""

F3::str := append(str, "chicken")
F4::str := append(str, "nugget")
F5::
SendInput % "{Text}" str
str := ""
Return

append(str, txt) {
 SoundBeep 1500
 Return Trim(str " " txt)
}
Or:

Code: Select all

#Requires AutoHotkey v1.1.33
str := ""
F3::str .= " chicken"
F4::str .= " nugget"
F5::
SendInput % "{Text}" Trim(str)
str := ""
Return
If you are new to AutoHotkey, you might want to try its current version (v2.x).

Code: Select all

#Requires AutoHotkey v2.0

str := ""

F3::Global str := append(str, "chicken")
F4::Global str := append(str, "nugget")
F5:: {
 Send "{Text}" str
 Global str := ""
}

append(str, txt) {
 SoundBeep 1500
 Return Trim(str " " txt)
}

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

Re: Copy 2 OCR data and merge into 1

Post by mikeyww » 06 Feb 2023, 11:39

OK. The concept is that when you have found your string, append it to a variable; repeat as needed. When finished, you can send the final output, and reset the output variable.

neasoo
Posts: 3
Joined: 05 Feb 2023, 22:52

Re: Copy 2 OCR data and merge into 1

Post by neasoo » 07 Feb 2023, 09:35

mikeyww wrote:
06 Feb 2023, 11:39
OK. The concept is that when you have found your string, append it to a variable; repeat as needed. When finished, you can send the final output, and reset the output variable.
Your reply lit a bulb in my head. After tinkering for about 2 hours, I managed to create what I want! Thank you Mike!

Result for anyone interested:

Code: Select all

Copy:
Gui, Submit, NoHide
{
	vvdata1 := OCR([343, 124, 87, 396], "eng")
	Sleep, 500
	str := append(str, vvdata1)
}
Gui, Show
return

append(str, txt) {
	SoundBeep 500
	Return Trim(str "" txt) "`n`n`n`n"
}

Load:
{
	str := ""
}



Paste:
Gui, Submit, Hide
{
	Clipboard := ""
	FormatTime, CurrentTime,, HH:mm
	Clipboard := CurrentTime "`n" str
	Sleep, 10
	Send, ^v
	str := ""
}
Gui, Show
return

Post Reply

Return to “Ask for Help (v1)”