Reading text within an app

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ElsePoem
Posts: 4
Joined: 11 Apr 2024, 17:16

Reading text within an app

13 Apr 2024, 13:11

Hello! A pretty new programmer trying to do something somewhat simple. I have been trying to get a script that can read text on screen within an app. Upon detection of that specific text I wanted it to pop up with a MsgBox letting me know that the specific text has been sent! I’ve tried everything i could but to no avail.
(I hope this code pastes correctly since i’m on mobile)
——————————————————————————————————————————

Code: Select all

Loop {                                                  ; Start Loop
    if (WinActive("ahk_exe *program*.exe"))               ; program is open
        {                                               
        WinGetText, text, ahk_exe program.exe           ; Get Text from program if open
        IfInString, text, "Warning!"                  ; Check if text is Warning!
        {                                           
            MsgBox "Warning DETECTED!"               ; If so, stop app
            ExitApp                                     ; Stops app
——————————————————————————————————————————
Please don't be afraid to tell me that this is complete gibberish if you know any help for the solution :lol:


[Mod edit: Added [code][/code] tags. Please use them yourself when posting code.]

[Mod action: Moved topic to the v1 section since this is v1 code. The main section is for v2.]
User avatar
mikeyww
Posts: 27196
Joined: 09 Sep 2014, 18:38

Re: Reading text within an app

13 Apr 2024, 17:06

Welcome to this AutoHotkey forum!

Perhaps:

Code: Select all

#Requires AutoHotkey v1.1.33.11
#SingleInstance
winTitle := "ahk_exe Notepad.exe"
find     := "Warning!"
Process Priority,, B
Loop {
 WinWait % winTitle
 SetTimer Go, 200
 SoundBeep 1500
 WinWaitClose
 SetTimer Go, Off
 SoundBeep 1000
}
Go:
WinGetText txt, % winTitle
If InStr(txt, find) {
 MsgBox 48, Warning, Warning detected!
 ExitApp
}
Return
If you are new to AHK, I recommend using its current version, which is v2, instead of this older deprecated version that is no longer developed.
ElsePoem
Posts: 4
Joined: 11 Apr 2024, 17:16

Re: Reading text within an app

13 Apr 2024, 17:46

Thank you!! it works perfectly! However I think now it seems to just be a problem with the api of the app I'm using or I'm not inputting the correct file name into my code, will check it out now! :D
User avatar
mikeyww
Posts: 27196
Joined: 09 Sep 2014, 18:38

Re: Reading text within an app

13 Apr 2024, 18:17

Window Spy will show whether WinGetText can retrieve the text.
ElsePoem
Posts: 4
Joined: 11 Apr 2024, 17:16

Re: Reading text within an app

13 Apr 2024, 18:45

I looked at what it was viewing and not as much as i was hoping for, I found “Chrome.ahk on github so maybe that can read more than what it can now
User avatar
mikeyww
Posts: 27196
Joined: 09 Sep 2014, 18:38

Re: Reading text within an app

13 Apr 2024, 19:09

Probably. I doubt that you would have much luck with WinGetText in a Web browser. UI Automation is available, with scripts posted on the forum.
ElsePoem
Posts: 4
Joined: 11 Apr 2024, 17:16

Re: Reading text within an app

13 Apr 2024, 19:12

Ill go search for some! thank you!
olyria18
Posts: 1
Joined: 07 May 2024, 14:17
Contact:

Re: Reading text within an app

07 May 2024, 14:24

ElsePoem wrote:
13 Apr 2024, 13:11
It's fantastic that you're diving into programming! For text recognition within an app, consider using libraries like OpenCV or Tesseract for image processing and text extraction. Break down your task into smaller steps, and don't hesitate to seek help from online communities or forums for guidance. Keep persisting.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 105 guests