4

I have a Java background so have limited knowledge when it comes to C# and C++. Basically I am trying to "read" text from another application which is displayed on screen...

enter image description here

To be specific, I want to read the dealer chat message from Pokerstars... on the fly...

What is the best way to read this text into a Java program on the fly? Ive head about API hooking, is this the only way and how would I do this in Java?

Thanks Phil

p_mcp
  • 2,643
  • 8
  • 36
  • 75
  • Its not cheating... Im building a Poker tracker software much like [Hold'em Manager](http://www.holdemmanager.com/) which is 100% legal, thank you – p_mcp Apr 25 '11 at 20:29
  • 1
    If he's just reading text that is already on his screen, it's hardly going to be cheating. – Puppy Apr 25 '11 at 20:29
  • @deadmg how would you write a poker bot without reading text on the screen? Anyway phil's explanation clears it up. – David Heffernan Apr 25 '11 at 20:33
  • I think a similar question has been asked and answered before here: http://stackoverflow.com/questions/352236/reading-from-a-text-field-in-another-applications-window I hope that helps you. – Bart Apr 25 '11 at 20:58
  • @PhilMcParlane how did you finally solved the issue? Did you used OCR as bmcnett adviced or you found a better way? I am facing similar issue as you did and OCR just seems pretty overkill to me. Thanks – Maarty Mar 14 '16 at 20:48
  • 1
    @Maarty unfortunately I ended up having to turning off text shadows on windows before scraping the actual *raw pixels* for different font characters (it was absolutely horrible and not something i would want anyone to go through). – p_mcp Mar 15 '16 at 00:13

2 Answers2

2

If the application you want to hook into is c# then maybe reflector is a good place to start.

http://reflector.red-gate.com/download.aspx?TreatAsUpdate=1

Another thing you wany want to look into is reading the network traffic and grabbing the data at that level. In which case take a look at wireshark.

http://www.wireshark.org/

You may be able tgo create a proxy, where data is directed through your application at the network level and you pass it on but read out the interesting parts.

Good Luck.

Angelom
  • 2,413
  • 1
  • 15
  • 8
  • So if I just listen to port 26002 (Pokerstars port) in Java and parse the data there? (Sorry Im not an expert in low level computing...) – p_mcp Apr 25 '11 at 21:34
2

One way to do it, which works as long as text is not anti-aliased, like in your image:

From your application, take a screenshot of the other application's window. Search the screenshot for all non-white pixels. Make a list of all the non-white pixels. For each pair of non-white pixels in the list, if the pair touches each other, put them in the same "group." Do this until all the pixels are grouped together.

Then for each group, compare its shape to a table of predefined shapes. If the shape isn't in the table, ask the user to type the letter, then save the shape and which letter it is to the table.

Now you have ASCII codes for all the letters in the window.

This is not the cleanest way to scrape text from a window, but it is hard to defeat. For any move made by the other application to make the text harder to read by a computer, it will become harder to read by a human, which lowers the usefulness of the application.

  • Hi I was hoping not to use OCR because I plan it to handle running multiple tables at once and I dont want lots of screenshots being passed about... thanks for your input anyway! – p_mcp Apr 25 '11 at 21:30
  • What I'm talking about is far less complicated than OCR. OCR would be capable of recognizing letters in practically any font. What I'm talking about can recognize only letters it's already seen with a precise bit pattern. –  Apr 26 '11 at 17:56
  • 2
    This is overkill. Go read on API Hooking (i.e. Detours or EasyHook) to read what the app is writing on the screen. – Marc Climent Jun 22 '11 at 18:06