Context:
I have been tasked with implementing the functionality to be able to retrieve the currently selected text of the active window then pressing a registered HotKey combo. Hotkeys registered with user32.dll RegisterHotKey
This is used to mark a phone number that will later be forwarded to a phone that will call this number, these phone numbers can come from a variety of places, some of these being: in app, email, database.
Problem:
The problem arises when the Chrome browser comes into the picture, Chome does not respond to SendKeys or anything I've thrown at it.
Question:
Using C#, how can I retrieve the currently marked text from a Chrome window, or any browser in general, as it needs to be compatible with whichever browser that the user prefers to use?
I've tried:
So far I've tried a lot of various methods and hacks, I've tried user32.dll sendmessage
, SendKeys
, AutomationElement
among other cheap hacks that has long since been overwritten as it was just throwing errors.
My currently working code is grabbed from Github. This works for the most part when using notepad++ among other things. Do note that this does not work with discord either.