r/csharp • • 7d ago

I built a hover-to-translate tool for Windows using UI Automation + Windows OCR (WPF, .NET 8, open source)

Hi r/csharp! I've been working on Cursor Translate, a small WPF app that translates the text under your mouse cursor in any Windows app, just by resting the mouse over it.

Demo and code: https://github.com/OdiazLz/CursorTranslate

Some technical bits I found interesting:

  • UI Automation first: AutomationElement.FromPoint gives the element under the cursor. In browsers that's usually a tiny text node, so I walk up the tree until something exposes TextPattern, then use RangeFromPoint + ExpandToEnclosingUnit to get the word, line or paragraph.
  • Windows OCR as a fallback (Windows.Media.Ocr) for images, PDFs and apps that don't expose text. It captures a strip around the cursor, groups OCR lines by column and paragraph, and finds the word closest to the cursor.
  • Sentence detection: finds the sentence around the cursor offset, skipping abbreviations like "e.g." or "Mr." and removing citation marks like [10].
  • Click-through tooltip: a WPF window with WS_EX_TRANSPARENT | WS_EX_NOACTIVATE so it never steals focus, positioned with the monitor work area so it stays on screen.
  • Translation fallback chain: DeepL (user's own key) → Google → MyMemory, with caching and throttling after hitting HTTP 429 a lot.

I'd really appreciate feedback, especially on the UI Automation part. In Chrome it often falls back to OCR, and I suspect it's about Chrome's accessibility mode. If anyone has dealt with UIA + Chromium before, I'd love to hear how you handled it.

Thanks!

0 Upvotes

15 comments sorted by

16

u/binarycow 7d ago

You built it? Or Claude built it?

0

u/Leading-Kangaroo-180 5d ago

Such a naive comment in 2026, you're aging yourself.

2

u/binarycow 5d ago

Call me crazy, but I think people should disclose if they used AI to write their code.

-6

u/ChanceInevitable3275 7d ago

Built it with Claude as a coding assistant — it wrote a lot of the code. I created classes, updated functions and worked on the UI design, plus the idea, testing, debugging and the releases. Any feedback on the approach is very welcome!

11

u/binarycow 7d ago

And you used it to write your post and comment here.

-8

u/ChanceInevitable3275 7d ago

My English isn’t that good, and I need it to help me write a bit better so that I can be understood without using idioms.

13

u/binarycow 7d ago • Bravo

You truly don't.

People would much rather read authentic writing than perfect writing.

2

u/ChanceInevitable3275 7d ago

Thank you very much; I will keep that in mind for future posts.

7

u/chucker23n 7d ago

People would much rather read authentic writing

And that goes for the code, too. There's no good explanation for why all these showcases lately are .NET 8 other than "it's what the LLM was trained on", so OP probably didn't make it.

If they had made it and it had half the features, I would be much more excited and encouraging.

6

u/zenyl 7d ago

Yeah, this post and repo stinks of low-effort vibecoded slop.

  • Title begins with "I built [...]" (alternatives include "I made [...]", or the slightly more spicy "I got tired of [...] so I built/made [...]")
  • Unnatural use of bold
  • Arrow characters in the post
  • Em-dashes in the README
  • Post has the obligatory bullet point list, usually places squarely in the middle of the post, flanked by two paragraphs, where the last paragraph asks for feedback.
  • Repo README has that obligatory project structure tree diagram with code formatting, because for some reason all LLMs have a hard-on for those.
  • Targeting .NET 8, because why would you ever doubt the word of an outdated LLM?

Not a single critical thought went into this project, or this post. OP just told an AI to do it all for them, and they followed it blindly and without a single objection. As you can imagine, vibecoders are usually too lazy to come up with anything more than a barebone prompt, so they all get output that sounds the exact same.

9

u/TrippyDe 7d ago

Yo, .net 8 is EOL, you should upgrade to .net 10

1

u/ChanceInevitable3275 7d ago

I am currently using this developed version, but I am in the process of updating it; thank you very much.

1

u/XalAtoh 7d ago

Thanks Claude, it is a dumb idea, but the code and the writing is cool.

1

u/[deleted] 7d ago

[removed] — view removed comment

-1

u/ChanceInevitable3275 7d ago

Yes, that’s why I was thinking of using a local model and caching, so that it could be used later for learning. Thanks for your feedback!