1

Is it possible to write a code that will copy text values from a window belonging to another application?

I have an application that gives me live results(only texts), every 5 minutes, and I cannot copy paste them every 5 min.

Screenshot

Dai
  • 141,631
  • 28
  • 261
  • 374
  • Does this answer your question? [Copy and Modify selected text in different application](https://stackoverflow.com/questions/235972/copy-and-modify-selected-text-in-different-application) – Code-Apprentice Mar 05 '20 at 23:15
  • unfortunately, no. I want the code to copy a text from a live list that another application provides. and it needs to do it automatically foe example each 10 minutes. – Peyman Javanbakht Mar 06 '20 at 09:04

1 Answers1

3

Maybe.

It depends on how the target application is exposing its text to the OS.

If the application is using a private 2D/drawing library to render text by itself to an in-memory or in-VRAM buffer, then no. You'll need to grab a screenshot and perform OCR on it - or you could inject your own code into the target process and intercept those 2D/drawing library calls to get the text being rendered.

If the application is using the Windows-provided GDI then there are ways of intercepting those calls to get the text. I believe Direct2D and DirectWrite also offer straightforward ways of intercepting/profiling their calls as well.

If the application is using a GUI framework or platform like WinForms or WPF then there are ways of inspecting the rendered view's object-model to extract data and text - this is how various "Spy" utilities work. "Spy++" (spyxx.exe included in Visual Studio and the Windows SDK) can inspect native Win32 hWnd windows and "Snoop" is a very powerful tool for inspecting WPF applications (Visual Studio's built-in Visual Inspector does the same thing).

Additionally, often GUI frameworks and platforms will support the OS' built-in Accessibility platform and will expose on-screen data as machine-readable structured data for use by screen-readers for the blind and visually impaired as well as automation software. Windows' built-in platform is called Active Accessibility and Windows UI Automation. There are premade tools you can download to inspect Active Accessibility data.

If it's a HTML application (e.g. Windows HTA, Electron app, Chrome desktop app, etc) then that's another topic.

Dai
  • 141,631
  • 28
  • 261
  • 374
  • Thank you so much for your time. so I ran spyxx.exe and for specified windows: class name: HwndWrapper[TMain.exe;;e9b5e87f-3be2-4556-baa5-cc269616ef1f] I'm really new to coding so please kindly excuse my lack of knowledge. so what is the next step? – Peyman Javanbakht Mar 06 '20 at 09:00
  • @PeymanJavanbakht `HwndWrapper` indicates the application is possibly using `pywinauto` or WPF. Judging by the screenshot you posted it's likely using WPF, so you can probably get text out of it using Snoop. – Dai Mar 06 '20 at 09:32
  • @PeymanJavanbakht Assuming it is a WPF application, then you should be able to programatically get the text using the Windows UI Automation API because WPF automatically exposes its DOM to Windows: https://learn.microsoft.com/en-us/windows/win32/winauto/entry-uiauto-win32 – Dai Mar 06 '20 at 09:35
  • wow, thank you so much, I really appreciate it man. I will do that now thanks again – Peyman Javanbakht Mar 06 '20 at 09:49
  • @PeymanJavanbakht I wish I could look as cool as you in sunglasses – Dai Mar 06 '20 at 10:00
  • thank you so much, you are very kind @Dai dude its really working!!! you are amazing, thank you, so the next step is to use the snoop code source in a c# to create my app??? – Peyman Javanbakht Mar 06 '20 at 10:34
  • @PeymanJavanbakht I wouldn't use Snoop's actual source code - but you should be able to use it as a project-reference (i.e. as a library). That's all I can tell you for now though as I've never actually worked with Snoop - and my time is billable :) – Dai Mar 06 '20 at 10:38
  • alright, thank you so much it was very nice talking to you. – Peyman Javanbakht Mar 06 '20 at 10:40
  • is there anyway that I can contact you to make you an offer to help me write the code? – Peyman Javanbakht Mar 06 '20 at 10:47