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

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.

Related

How to paste text into a different application with C#

Here is my scenario:
A user has two applications open. Let's say one application is Notepad with some text in it and the other one is my C# application.
A user now positions the mouse cursor somewhere inside the Notepad text and then clicks a button in my C# application. As a result, a text string from my application gets pasted in Notepad where the cursor was positioned.
My question is: what would a general approach be to accomplish the above, and possibly what classes etc. are recommended?
I would look into using interop calls to accomplish this. Look at specifically GetWindow() and SendMessage with the WM commands (http://msdn.microsoft.com/en-us/library/windows/desktop/ms644927(v=vs.85).aspx#system_defined) and GetDesktop().
GetDesktop will allow you to obtain all of the top level child windows of the desktop (all top level windows are children of the Desktop window).
You should then be able to use GetWindow to obtain the window handle you are looking for and then SendMessage to set the text into the textbox.

How to know selected text with 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.

How to capture keystrokes before the foreground window gets it?

I'm doing an application like Google Transliteration (Google input tools) tool in C#. It displays the suggestion window on the top of whatever window we are typing (finds caret location & display just window below it). But the focus (foreground process) is still on the application in which we type (for eg. Ms Word, Notepad etc.).
I want to implement these features of Google Transliteration:
It captures the keystrokes before another process gets it.
While renaming a folder or file, we can select words from the suggestions
window show up by using up & down arrow keys and press enter key. But the
rename text field will be still active. The keystrokes will be
captured before it reaches rename text field.
I want to implement a universal text suggestion list (window) like that of Google Transliteration.
How to capture keystrokes before another process gets it (block foreground process from getting it)? (Main Question)
How to capture keystrokes (up & down arrow keys and enter key) and select an option from the words list without focusing on the 'words list' window?
(Caret should remain active and blinking on the foreground process text field. eg. Folder rename text field)
Someone please help me to solve this problem.
I already found this one, but it not helped me to solve my problem.
Capturing keystrokes without focus
You mix two different problems. The first problem - to catch keyboard input - nothing to do with the second - to make an unfocusable window.
The solution to the first problem is very simple - as stated in your link, there is no other way to do it other than Low-Level windows hooks.
The second problem is more difficult, the solution may require a little experimentation, creativity and knowledge of WinAPI. Examples are here, here and here.

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 make a right-click translation dictionary application?

I'm trying to write a dictionay application on C#. There is a scenarios that user selects a text and press a hot-key, I want to pop-up a quick windows that display the search result of the selected word (just like Lingoes does)
How would I do it in C#?
Thanks in advance
Start with Google this:
hooks, global hotkeys (for monitoring global keyboard and mouse events)
WinAPI (to do such tricks as grab any selected text)
I've written program you're talking about. You can check the code here - IDictionary.
Regards

Categories

Resources