Capture selection from other applications?

  • Thread starter Thread starter Figmo
  • Start date Start date
F

Figmo

I am writing a language translation app. It will run minimized to
the tray. I want to setup a global hotkey that a user can hit that
will capture whatever text is highlighted in the current window and
translate it. The current app could be a web browser, Word, Notepad,
whatever.

Can somebody give me some help on what API's to call to get a handle
to whatever window (from whatever application) has focus so that I can
get selected text?
 
I think that you answered this before, or a very similar question was
asked in the past month.

Regardless, there really is no way to unify access to every single
application. The way that you would get the selected text in word is
different from the way that you would get it in notepad, and so on, and so
on.

I think the best bet to do something like this would be to use the
Accessibility APIs, which would allow you to get the text currently in
focus/highlighted/selected, and then work from there. However, this assumes
that all apps are accessible, and in the case that they are not, you will
have to find some sort of default behavior.
 
I think the best bet to do something like this would be to use the
Accessibility APIs, which would allow you to get the text currently in
focus/highlighted/selected, and then work from there. However, this assumes
that all apps are accessible, and in the case that they are not, you will
have to find some sort of default behavior.

--

OK so what about using the clipboard? If I can get the handle for
the currently focused window could I then send a CTRL-C to the
application and then query the clipboard for the text? This would be
pretty close to universal. There may be a few apps out there that
don't have clipboard support but the vast majority of apps a person
would want translation support for would support the clipboard
(Browser, Word processing, Email, etc)

Which I guess brings me right back to the original question (or at
least half of it). How to get the window handle of the current focus
window (regardless of thread).
 
Ctrl-C is common, it's not universal. On top of that, the idea of
replacing what is on the user's clipboard is pretty rude from an application
standpoint, and users would be confused as to why their clipboard contents
are being erased when they use your app.

Use the accessibility API, it's the best option, IMO.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top