Condition when mouse hovers selected text

Is it possible to create a condition that checks if the mouse cursor is hovering over selected text?
I’d like to trigger an action only when the cursor is over text that is currently selected. Is there any built-in way to achieve this, or would I need to use AppleScript or another workaround?

I don't think there is a universal way to achieve this. What are you trying to do?

This seems tricky. The only solution I can think of is to use real-time OCR, but that might be really slow.

I'm trying to replicate the copy/paste behavior from the Windows Terminal. The way it works there is:

  • If I select text and right-click, it copies the selected text.
  • If no text is selected and I right-click, it pastes whatever is on the clipboard.

I've gotten most of this working in BetterTouchTool, but I'm running into one issue:
It currently copies text even if I'm not right-clicking directly on the selected text—just somewhere else in the terminal window.