capturing highlighted text from a web browser using c# -
I have a project that needs to capture the highlighted text from the web browser (Chrome, Firefox etc.) . In my project, the user highlights a text, for example a word from the web browser And this program translates words to the language that was selected before using Google Translate. I have been able to capture highlighted text from some applications like Notepad, but I need to do this especially with a web browser
Can anyone help me with that? I searched all the documents and tried all the methods but I could not achieve my goal. This project is for my college graduation.
I would appreciate some help here. Thanks !!
Place it at the top of your class:
[DllImport ( "User32.dll")] Fixed Exerture Zero KeyBytes (Byte BVK, Byte BSKen, UIT Dwlags, UIT DAFRINFO); Then a method to get the text
Fixed UIT KEYEVENTF_KEYUP = 2; Static Byte VK_CONTROL = 0x11; Public static string gettext () {string message; Try {Thread. Sleep (100); Message = Clipboard.GetText (); Return message; } Hold (exception) {gettext (); }} Public Static String Highlight () {string output; Keybd_event (VK_CONTROL, 0,0,0); Key_edit (0x43, 0, 0, 0); Keybd_event (0x43, 0, keyInstant_KEYUUP, 0); Key_events (VK_CONTROL, 0, keyvanti_kayupup, 0); Production = gettext (); Return output; } Note: Sometimes the clipboard is in use and will give an exception so that you need to try and catch, if it captures the exception, do not repeat it again.
The advantage of using these codes:
1. If you just want something in the clipboard, gettext ()
Call 2 highlighted text For, call HighlightText ()
Anyone can edit my posts by looking at errors.
Thanks
EDIT: Adding static is used for the main (). If you do not use it with the main, then stabilize
Edit2 !!: Adding the static for all external variables !! Please tell me another error.
Comments
Post a Comment