How to know selected text with C#? - c#

Can someone tell me how to read selected text with C#?
I need it to work outside of my app.
For example, the user opens a Notepad, writes something, selects text, and presses a hotkey.
I need to store the text in a variable in my program. How can I do that?
Thank you in advance.

you could read the text from a notepad window via PInvoke. SendMessage function from user32.dll...
Here is a example http://loyaltyhf.blogspot.com/2013/01/source-chrome-class.html that reads the address from Google Chrome's Address bar. It might not work for the current version of Google Chrome but it'll give you a pretty good idea.

Related

Write into website cell using c# or WPF application

I have a very strange request that might upset some of you, anyway I want to write text or numbers in the website using C# or wpf software.
What I want is I pass string or number to the website when I press for example F11 on the keyboard and that number or string can be from a textbox.
Assume the following is Grid on a website:
Now I want to pass 0.01233 from textbox, to the highlighted cell in the website using c#.
Can anyone please how this can be achieved or at least guide me which direction I should go and achieve this.
Please Note I am not a developer of website and I have no control on website, I cannot write script on website
I've done something like this before, though I can't seem to find my old code. WPF has a WebBrowser control. You can use the Document property to access elements of the webpage an (if I recall correctly) execute scripts assosiated with those elements.
Of course it goes without saying that this would be a bodge at best, since any change made to the website could break your code.
Also, this forces you to use the WPF WebBrowser instead of your browser of choice.

How to paste data from clip board to focused text control in web page?

I am working on project where I want to paste data from clipboard to last focused webpage's text control(like text box for username or password).
The web page will be opened in Chrome\FF\Safari Web Browser.
This all task will be done on click of "Paste" button in my application.
I have handle of last used application including web Browser (Other than my application).
So can any one help me on this?
Sorry for bad English.
if any more information expected please comment.
Thank you in advance.
You first have to "activate" the target window, in order to really have a focused text box.
See that answer in order to do that.
Then, you'll have to fake a "Paste" keyboard command using SendInput.

How to get the highlighted text on any windows applications (word, sharepoint portal, web browser)

I am developing an c# application.
Whenever my window gets activated, I want to get the highlighted/selected text on any windows applications (like word, excel, sharepoint portal, web browser, etc.,).
How to do this with C#?
I will really appreciate if someone comes up with a small sample instead of suggesting the links.
Thanks in Advance !
Let me explain it again in detail
I have to create a search application in c#.
Suppose if i select a text "vimal" in internet explorer (or word or excel or any application) and open the Search application then word "vimal" should be displayed in the search application.
Hope the requirement is clear now.
This is impossible for any application. Every application handles text differently.
They may have multiple (rich or not) text boxes that keep the text selected, etc.
Some other applications might use custom controls with custom selection logic...
This is impossible. Correct me if I am wrong (but it won't be the case).
Edit: Read the second answer in your own link.

How to write text to an external application

I'm developing an application to help the user write common text faster.
What I have in mind is a Windows app where the user can configure his key combinations, so that when he's, for instance, writing an email on Outlook or Gmail, he just has to press those keys and the text he configured before will be pasted into whatever app he's using.
So, instead of a user having to write "Dear sir, your order has been received succesfully" every time he receives an order and wants to send a confirmation email, he could just press something like "Crtl + O + R", and the corresponding text will be written for him.
I think that in order to achieve that my app has to do two things:
Intercept the key combination pressed buy the user when he's focused on a different app.
"Paste" the corresponding text to that app.
I have no real clue on how to achieve this, because what my app will be doing is something like "pasting" text on another app (otlook, word, notepad or whatever thing a user can type into), replacing the short text the user wrote with the long text he defined.
Any suggestions? I've looked into hot keys, but I'm not sure they're the way to go, and I also have no idea on how to "paste" the new text.
Thanks.
Have you considered simply adding text to the clipboard? Show the text next to a button that says "Copy to clipboard", and the user can just grab it and click Ctrl-V.
Can't think of a Windows app that does it this way, but I know it's possible; heck, Bit.ly can do it from your browser.

How to get text clicked from another program into your own textbox?

What I mean is how can I get text from another running active window. For example I have a program let's say word or msn. I am chatting with someone while my own program is running in the tray. I want to set a key let's say right click and ctrl to open up my program and get the word I clicked on.
I am using C#.
I direct you to my answer to the question Unified way to scrape HTML from any type of browser process
The answer links to an article on Coding the Wheel which details how to access text in other windows via system dll hooks. That should have what you require.
you could copy the word and then get the word out of the clip board in your application... otherwise your talking API's for any application you might was to get a word from.

Categories

Resources