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.

2 Answers 2

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.

2
  • 1
    Copies 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. docs.microsoft.com/en-us/windows/win32/api/winuser/…
    – Mark
    Commented Feb 21, 2020 at 18:03
  • @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. Commented Feb 21, 2020 at 18:45
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
2
  • 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 Commented Feb 24, 2020 at 10:45
  • 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.
    – Cpt.Whale
    Commented Feb 25, 2020 at 14:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .