Accessing displayed content of external programs

1

This has been a longstanding difficulty for me, and I don't know (even after googling) what the easiest solution to this is.

I have an external program (coherent laser software) that displays some data.

Is there a way how I can access the content of any displayed text in any currently opened window, within windows? Can something like a hook be achieved in powershell?

Ideally I'd want to read out and save the current set-value of the laser, as displayed by the GUI.

user2305193

Posted 2020-02-21T14:35:37.087

Reputation: 113

Answers

1

If you can install the free portable application GetWindowText or an alternative on the OS where the coherent laser software resides, that might capture the text. GetWindowText worked well with Notepad, but did not copy text from another application I tried.

A second choice would be to have the external app create a text file as output, to review later or to be sent to your PC.

It might be easiest to just take a screen-shot from your local PC and then use optical software recognition (OCR) software to get the text. Try FreeOCR or one of the many alternatives. Caveat: OCR occasionally misreads text.

DrMoishe Pippik

Posted 2020-02-21T14:35:37.087

Reputation: 13 291

1Copies the text of the specified window's title bar (if it has one) into a buffer. If the specified window is a control, the text of the control is copied. However, GetWindowText cannot retrieve the text of a control in another application. https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowtexta – Mark – 2020-02-21T18:03:14.770

@Mark, the application in the reference is not the Windows API call GetWindowsText(), though it has a similar name. From the URL above: "Copy a window's text content quickly and easily by dragging the application's crosshair icon over the required text source using this portable application." That should have been obvious, because it needs to be installed, and is not native API. – DrMoishe Pippik – 2020-02-21T18:45:00.067

1

AutoHotKey is a great Batch-style tool designed for this kind of thing. In general, the steps will be:

  1. With the laser software open, run the included Windows Spy utility
  2. Mouse over the text field (control) you want, and note the ClassNN of the control
  3. In your AHK script, use ControlGetText to store the value as a variable
  4. As an example, to get the window text then pass to a powershell script:

AHK:

ControlGetText, MyVar, MyClassNN, MyTitle
Run, powershell.exe "C:\MyScript.ps1 %MyVar%"

Powershell:

$setvalue = $args[0]
# do stuff

user19702

Posted 2020-02-21T14:35:37.087

Reputation: 361

thanks for the great reply. How reliable is AutoHotKey if it runs in the background? This should be completely foreground and user independent, i.e. it should not switch active windows for example. I'll look into how AutoHotKey extracts this information – user2305193 – 2020-02-24T10:45:48.703

AHK is fine, but you might choose to have a different script start the AHK script rather than having it run in the background, depending on what you need and how often you need it. I'm not sure from memory, but I doubt it cares much about the active window since it accesses windows by name/instance ID. – user19702 – 2020-02-25T14:46:32.307