0

I have a translation application for a niche language.
If the user selects/highlights text (typically in the browser) I want the translation func to get triggered. It manually checks and if the language is detected it translates.

I do have my onMouseUp Listener that triggers. However I don’t know how to get the selected text, how to put it into a variable (without triggering ctrl+c and possibly overwriting the users clipboard)

Iam not sure what I am trying to do is possible.

Is it possible to get the users selected/highlighted text in an other app (browser), without triggering ctrl+c and clipboard?

Used pyperclip package however since it uses clipboard it overrides the users current clipboard text which might be important to the user.

MickyB
  • 1
  • 2

1 Answers1

0

So it is not a problem for you to use the clipboard, provided you can keep the old clipboard -- right? So would it be possible for you to save the old clipboard first. Do whatever you want to do and then later restore the clipboard?

Some ideas when using Windows: How do I read text from the clipboard? From there specifically this one could help gross-platform.

LMJay
  • 1
  • 1
  • What if the user modifies the clipboard in between the time the dev saves the old clipboard and the time the dev restores it? – Perplexabot Oct 25 '22 at 17:33
  • Unfortunately this is a very bad approach which I have been using so far. It is even worse if the user has multi-clipboard enabled because it messes up the clipboard history, especially since some users trigger the function a few hundred times a day. That’s why I was looking for a non-clipboard approach, something like an api to the browser or win app but I didn’t find anything – MickyB Oct 25 '22 at 17:40
  • Good points. So the aim is to have a drag-and-drop type of functionality without the actual physical drag and drop task. – LMJay Oct 25 '22 at 21:18