Help with text recognition

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Help with text recognition

21 Mar 2018, 03:38

So from an ocr I get this text on my clipboard:

Code: Select all

Getting server address...
Located server, connecting...
Logging on Verdicts...
Welcome back, Verdicts. 5 friends are online.
Get more Gems for your money! And go kiss the in
the worlds BlARN EY‘I - BlARNEY?!
Personal Settings active: Broadcasts hidden , _
Where would you like to go? (34,318 online) -7 ;
World AWH DIANGAWGAGAWG entered. There are 0 other people here, 34,328 online.
/msg verdicts hello dear
>> (Sent to Verdicts)
>> Private msg from Verdicts (in AWHDIANGAWGAGAWG) : hello dear .
I want the script to detect >> Private msg and when it does, it should save the entire line that is >> Private msg from Verdicts (in AWHDIANGAWGAGAWG) : hello dear . and continue searching for >> Private msg. It should not save the same line twice.

Also it should make note of the word after >> Private msg from in a variable. And also the letters inside the brackets in another variable.


I'm clueless it would be great if someone could help. :crazy:
I am your average ahk newbie. Just.. a tat more cute. ;)
Guest

Re: Help with text recognition

21 Mar 2018, 06:35

Pal just keep it simple, parse each line and use InStr, basically a three line script. Checkout OnClipboardChange if you want it to run automatically each time the clipboard updates - You can of course expand it by checking if the clipboard has the required string, if not you can skip the parsing loop. Sure you can use regex to "grep" (you can search for "grep autohotkey" to find various regex/more complex solutions) but keep it simple if you don't want more "options"

Code: Select all

clipboard=
(join`r`n
Getting server address...
Located server, connecting...
Logging on Verdicts...
Welcome back, Verdicts. 5 friends are online.
Get more Gems for your money! And go kiss the in
the worlds BlARN EY‘I - BlARNEY?!
Personal Settings active: Broadcasts hidden , _
Where would you like to go? (34,318 online) -7 ;
World AWH DIANGAWGAGAWG entered. There are 0 other people here, 34,328 online.
/msg verdicts hello dear
>> (Sent to Verdicts)
>> Private msg from Verdicts (in AWHDIANGAWGAGAWG) : hello dear .
)

loop, parse, clipboard, `n, `r
	if InStr(A_LoopField, ">> Private msg")
		PrivateMessages .= A_LoopField "`n"

MsgBox % PrivateMessages		
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: Help with text recognition

21 Mar 2018, 07:13

Guest wrote:Pal just keep it simple, parse each line and use InStr, basically a three line script. Checkout OnClipboardChange if you want it to run automatically each time the clipboard updates - You can of course expand it by checking if the clipboard has the required string, if not you can skip the parsing loop. Sure you can use regex to "grep" (you can search for "grep autohotkey" to find various regex/more complex solutions) but keep it simple if you don't want more "options"

Code: Select all

clipboard=
(join`r`n
Getting server address...
Located server, connecting...
Logging on Verdicts...
Welcome back, Verdicts. 5 friends are online.
Get more Gems for your money! And go kiss the in
the worlds BlARN EY‘I - BlARNEY?!
Personal Settings active: Broadcasts hidden , _
Where would you like to go? (34,318 online) -7 ;
World AWH DIANGAWGAGAWG entered. There are 0 other people here, 34,328 online.
/msg verdicts hello dear
>> (Sent to Verdicts)
>> Private msg from Verdicts (in AWHDIANGAWGAGAWG) : hello dear .
)

loop, parse, clipboard, `n, `r
	if InStr(A_LoopField, ">> Private msg")
		PrivateMessages .= A_LoopField "`n"

MsgBox % PrivateMessages		
Thanks! What about retrieving what is inside < > from the string that has >> Private msg?
I am your average ahk newbie. Just.. a tat more cute. ;)
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Help with text recognition

21 Mar 2018, 09:20

A little brutal but working script. Surely some Regex guru can make it shorter and smarter.
Maybe could helps.
Cheers.

Code: Select all

str=
(
Getting server address...
Located server, connecting...
Logging on Verdicts...
Welcome back, Verdicts. 5 friends are online.
Get more Gems for your money! And go kiss the in
the worlds BlARN EY‘I - BlARNEY?!
Personal Settings active: Broadcasts hidden , _
Where would you like to go? (34,318 online) -7 ;
World AWH DIANGAWGAGAWG entered. There are 0 other people here, 34,328 online.
/msg verdicts hello dear
>> (Sent to Verdicts)
>> Private msg from Verdicts (in AWHDIANGAWGAGAWG) : hello dear .
Logging on Verdicts...
Welcome back, Verdicts. 5 friends are online.
Get more Gems for your money! And go kiss the in
the worlds BlARN EY‘I - BlARNEY?!
Personal Settings active: Broadcasts hidden , _
Where would you like to go? (34,318 online) -7 ;
World AWH DIANGAWGAGAWG entered. There are 0 other people here, 34,328 online.
/msg verdicts hello dear
>> (Sent to Verdicts)
>> Private msg from Idontknowho (in SAGSHGSFHAFSHGF) : bye bye dear .
the worlds BlARN EY‘I - BlARNEY?!
Personal Settings active: Broadcasts hidden , _
Where would you like to go? (34,318 online) -7 ;
World AWH DIANGAWGAGAWG entered. There are 0 other people here, 34,328 online.
/msg verdicts hello dear
>> (Sent to Verdicts)
>> Private msg from Anotherone (in FLKJSDFLKJSDLKJ) : so long my dear .
)
loop, parse, str, `n, `r
	if InStr(A_LoopField, ">> Private msg")
		PrivateMessages .= A_LoopField "`n"
while RegExMatch(PrivateMessages, "O`am)from\s+\K(\w*)", num, A_Index = 1 ? 1 : num.Pos + num.Len)
	strx .= "From# " A_index "`t" num.value "`n"
while RegExMatch(PrivateMessages, "O`am)\(in\s+\K(\w*)", num, A_Index = 1 ? 1 : num.Pos + num.Len)
	strx .= "In# " A_index "`t" num.value "`n"
while RegExMatch(PrivateMessages, "O`am):\s+\K(.*)", num, A_Index = 1 ? 1 : num.Pos + num.Len)
	strx .= "Msg# " A_index "`t" num.value "`n"

msgbox %strx%
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: Help with text recognition

21 Mar 2018, 11:29

Odlanir wrote:A little brutal but working script. Surely some Regex guru can make it shorter and smarter.
Maybe could helps.
Cheers.

Code: Select all

str=
(
Getting server address...
Located server, connecting...
Logging on Verdicts...
Welcome back, Verdicts. 5 friends are online.
Get more Gems for your money! And go kiss the in
the worlds BlARN EY‘I - BlARNEY?!
Personal Settings active: Broadcasts hidden , _
Where would you like to go? (34,318 online) -7 ;
World AWH DIANGAWGAGAWG entered. There are 0 other people here, 34,328 online.
/msg verdicts hello dear
>> (Sent to Verdicts)
>> Private msg from Verdicts (in AWHDIANGAWGAGAWG) : hello dear .
Logging on Verdicts...
Welcome back, Verdicts. 5 friends are online.
Get more Gems for your money! And go kiss the in
the worlds BlARN EY‘I - BlARNEY?!
Personal Settings active: Broadcasts hidden , _
Where would you like to go? (34,318 online) -7 ;
World AWH DIANGAWGAGAWG entered. There are 0 other people here, 34,328 online.
/msg verdicts hello dear
>> (Sent to Verdicts)
>> Private msg from Idontknowho (in SAGSHGSFHAFSHGF) : bye bye dear .
the worlds BlARN EY‘I - BlARNEY?!
Personal Settings active: Broadcasts hidden , _
Where would you like to go? (34,318 online) -7 ;
World AWH DIANGAWGAGAWG entered. There are 0 other people here, 34,328 online.
/msg verdicts hello dear
>> (Sent to Verdicts)
>> Private msg from Anotherone (in FLKJSDFLKJSDLKJ) : so long my dear .
)
loop, parse, str, `n, `r
	if InStr(A_LoopField, ">> Private msg")
		PrivateMessages .= A_LoopField "`n"
while RegExMatch(PrivateMessages, "O`am)from\s+\K(\w*)", num, A_Index = 1 ? 1 : num.Pos + num.Len)
	strx .= "From# " A_index "`t" num.value "`n"
while RegExMatch(PrivateMessages, "O`am)\(in\s+\K(\w*)", num, A_Index = 1 ? 1 : num.Pos + num.Len)
	strx .= "In# " A_index "`t" num.value "`n"
while RegExMatch(PrivateMessages, "O`am):\s+\K(.*)", num, A_Index = 1 ? 1 : num.Pos + num.Len)
	strx .= "Msg# " A_index "`t" num.value "`n"

msgbox %strx%
Very nice! The problem is that it doesn't identify if the string already exists, so if you put a hotkey above the script and run it, you will see that the messagebox keeps getting those values added. With an ocr I will be looping and often times the old text will remain in the script, so this can pose a problem!

Really appreciate it my dude! :thumbup:
I am your average ahk newbie. Just.. a tat more cute. ;)
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Help with text recognition

21 Mar 2018, 12:51

Perhaps:

Code: Select all

str=
(
Getting server address...
Located server, connecting...
Logging on Verdicts...
Welcome back, Verdicts. 5 friends are online.
Get more Gems for your money! And go kiss the in
the worlds BlARN EY‘I - BlARNEY?!
Personal Settings active: Broadcasts hidden , _
Where would you like to go? (34,318 online) -7 ;
World AWH DIANGAWGAGAWG entered. There are 0 other people here, 34,328 online.
/msg verdicts hello dear
>> (Sent to Verdicts)
>> Private msg from Verdicts (in AWHDIANGAWGAGAWG) : hello dear .
Logging on Verdicts...
Welcome back, Verdicts. 5 friends are online.
Get more Gems for your money! And go kiss the in
>> (Sent to Verdicts)
>> Private msg from Verdicts (in AWHDIANGAWGAGAWG) : hello dear .
Logging on Verdicts...
Welcome back, Verdicts. 5 friends are online.
Get more Gems for your money! And go kiss the in
the worlds BlARN EY‘I - BlARNEY?!
Personal Settings active: Broadcasts hidden , _
Where would you like to go? (34,318 online) -7 ;
World AWH DIANGAWGAGAWG entered. There are 0 other people here, 34,328 online.
/msg verdicts hello dear
>> (Sent to Verdicts)
>> Private msg from Idontknowho (in SAGSHGSFHAFSHGF) : bye bye dear .
the worlds BlARN EY‘I - BlARNEY?!
Personal Settings active: Broadcasts hidden , _
Where would you like to go? (34,318 online) -7 ;
World AWH DIANGAWGAGAWG entered. There are 0 other people here, 34,328 online.
/msg verdicts hello dear
>> (Sent to Verdicts)
>> Private msg from Anotherone (in FLKJSDFLKJSDLKJ) : so long my dear .
)
loop, parse, str, `n, `r
	if InStr(A_LoopField, ">> Private msg")
		PrivateMessages .= A_LoopField "`n"
Arr := Object()	
while RegExMatch(PrivateMessages, "O`am)from\s+\K(\w*)", num, A_Index = 1 ? 1 : num.Pos + num.Len) {
	strx1 := num.value 
	RegExMatch(PrivateMessages, "O`am)\(in\s+\K(\w*)", num, A_Index = 1 ? 1 : num.Pos + num.Len)
	strx2 := num.value 
	RegExMatch(PrivateMessages, "O`am):\s+\K(.*)", num, A_Index = 1 ? 1 : num.Pos + num.Len)
	strx3 := num.value 	
	if ( Arr.Haskey(strx1) )
		MsgBox % "This entry alredy exists. >>" strx1 "<< thus will not be added to the array."
	else
		Arr[strx1] := {in:strx2,msg:strx3}
}
for i,v in Arr
	msgbox % i "`t" v.in "`t" v.Msg

ExitApp

I've on purpose duplicated one of the ">> Private msg " entry to show that it's not stored in the final array.
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
User avatar
Nwb
Posts: 444
Joined: 29 Nov 2016, 08:56

Re: Help with text recognition

22 Mar 2018, 04:30

Odlanir wrote:Perhaps:

Code: Select all

str=
(
Getting server address...
Located server, connecting...
Logging on Verdicts...
Welcome back, Verdicts. 5 friends are online.
Get more Gems for your money! And go kiss the in
the worlds BlARN EY‘I - BlARNEY?!
Personal Settings active: Broadcasts hidden , _
Where would you like to go? (34,318 online) -7 ;
World AWH DIANGAWGAGAWG entered. There are 0 other people here, 34,328 online.
/msg verdicts hello dear
>> (Sent to Verdicts)
>> Private msg from Verdicts (in AWHDIANGAWGAGAWG) : hello dear .
Logging on Verdicts...
Welcome back, Verdicts. 5 friends are online.
Get more Gems for your money! And go kiss the in
>> (Sent to Verdicts)
>> Private msg from Verdicts (in AWHDIANGAWGAGAWG) : hello dear .
Logging on Verdicts...
Welcome back, Verdicts. 5 friends are online.
Get more Gems for your money! And go kiss the in
the worlds BlARN EY‘I - BlARNEY?!
Personal Settings active: Broadcasts hidden , _
Where would you like to go? (34,318 online) -7 ;
World AWH DIANGAWGAGAWG entered. There are 0 other people here, 34,328 online.
/msg verdicts hello dear
>> (Sent to Verdicts)
>> Private msg from Idontknowho (in SAGSHGSFHAFSHGF) : bye bye dear .
the worlds BlARN EY‘I - BlARNEY?!
Personal Settings active: Broadcasts hidden , _
Where would you like to go? (34,318 online) -7 ;
World AWH DIANGAWGAGAWG entered. There are 0 other people here, 34,328 online.
/msg verdicts hello dear
>> (Sent to Verdicts)
>> Private msg from Anotherone (in FLKJSDFLKJSDLKJ) : so long my dear .
)
loop, parse, str, `n, `r
	if InStr(A_LoopField, ">> Private msg")
		PrivateMessages .= A_LoopField "`n"
Arr := Object()	
while RegExMatch(PrivateMessages, "O`am)from\s+\K(\w*)", num, A_Index = 1 ? 1 : num.Pos + num.Len) {
	strx1 := num.value 
	RegExMatch(PrivateMessages, "O`am)\(in\s+\K(\w*)", num, A_Index = 1 ? 1 : num.Pos + num.Len)
	strx2 := num.value 
	RegExMatch(PrivateMessages, "O`am):\s+\K(.*)", num, A_Index = 1 ? 1 : num.Pos + num.Len)
	strx3 := num.value 	
	if ( Arr.Haskey(strx1) )
		MsgBox % "This entry alredy exists. >>" strx1 "<< thus will not be added to the array."
	else
		Arr[strx1] := {in:strx2,msg:strx3}
}
for i,v in Arr
	msgbox % i "`t" v.in "`t" v.Msg

ExitApp

I've on purpose duplicated one of the ">> Private msg " entry to show that it's not stored in the final array.
Thanks a lot it does the job!
I am your average ahk newbie. Just.. a tat more cute. ;)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, arcylix, drani, Google [Bot], Rohwedder and 210 guests