Right click, text capture - c#

I have a c# application that runs in the bottom right corner of the page, i was wondering how i could go about making my application appear when the user selects some text anywhere (say a pdf, browser etc) and then right clicks, goes to my custome selection bit say and it pastes that text in to my running application.
If anyone made any sense of that could you advise me in to what i need to be researching to get it done.
Thanks

I've got this dictionary which does something similar.
Here's its mode of operation (or at least what I think it does)
When there is a double click, it sends a key command (probably Ctrl+C) to copy the selected text. It then reads the text from the clipboard.
For your purpose, you could implement the mouse listening and sending keystrokes with this article I found on CodeProject: InputManager library.
You then retrieve the copied text from the clipboard and do whatever you want with it.

Have a look at a Clipboard monitor

You can hook into the windows messaging api, probably there is a Text-selected event.

Related

Trying to detect and gather data on click outside application

I would like to know if it is possible to, while running a WPF window application in Visual Studio, wait for the user to click anywhere on the screen (not necessarily inside the window of my application - for the purpose of my application, the click would most likely occur inside a browser page) and then gather the information about the click (like inside the window of which application the user clicked, or the selector of the html element the user clicked)? I know this question might be very confunsing but this is basically my last resort since researching on the Internet hasn't helped me much. Just to provide a better idea of what I seek, it's like what the 'Extract Structured Data' Activity does in UiPath. Oh and I'm using C# by the way.
You can try and use this external library called GlobalMouseHook.
This library allows you to tap keyboard and mouse, detect and record their activity even when an application is inactive and runs in background.
Here is what you can do with this library:
Mouse coordinates
Mouse buttons clicked
Mouse drag actions
Mouse wheel scrolls
Key presses and releases
Special key states
Hope this helps.

How to handle an external HID button click in C#

I'm trying to integrate a third party hardware to one of my existing projects . Basically the hardware has two buttons with different color leds on each button.
I am able to open and close each led with the library/manual which is provided by the manufacturer without any problem. My problem is I can not handle its buttons click events from any kind of software C/C#/VB etc...
I mean when I press one of its buttons it acts like any input device and effects the cursors current position like a keyboard key or mouse click due the opened program(For example if Ms Word is opened currently it acts like space key?). The DLL or manual has no special function for this purpose (like a mouse click event?).
So what I'm asking is there any general way to handle any external device button click inside a C# program? How the currently running software suppose to understand a button is clicked and enter the desired method in the code?
Any clue or tip would be highly appreciated.
Thanks...

How to tail text from a specific control from an external program?

I have tried inspecting this window using Inspect.exe provided on Windows' 8.1 Software Development Kit Testing Tools. I couldn't seem to identify the control handle for this huge rich textbox like control. I could however get the control handle of the edit box below the textbox. I was hoping I could talk directly to the control and use a library such as WindowScrape to get the text.
I believe the external program is created in VC++ . If that helps.
This is the window. I am trying to get text from that is boxed in red color. This is a chat window , messages come in every 5 to 10 seconds. This box scrolls automatically. I want to tail through the text and get the latest message.
Is there any other way to accomplish this?
Tesseract maybe, but I do not know where to start to monitor a specific position relative to the window. So that when I move the window it will still be able to monitor that window.
Can you provide a screenshot of Inspect results showing both the tree and details panes while selecting the chat box?

How to trap Drag/Drop event in Word?

I am creating an Add-in (using C#) for Microsoft Word and want to trigger some functionality when some text/image etc. is dragged from any source and dropped into Word. So basically I want to trap the Drop event in Word. However I am not able to find any Word API which helps in this. Can you please help in this?
No such beast exists.
The best (easy-ish) approach you can hope for is to watch the DocumentChange event, and try to monitor what changed (it'll be located at the current location of the "Selection").
A much hardy way would be to subclass the main Word Window and watch for whatever Drag/drop messages are being exchanged, and intercept them as appropriate.
The SelectionChange event can sometimes be used for this. Sometimes, because the selection will not always contain the dropped content. E.g. if you drop an image into a document, the image will not be selected.
A better alternate is to use a transparent window that you overlay on top of the Word window. This window is initiated when the drag process starts and placed on top of the document window. The drop operation is then received by this window instead of Word, so you know exactly what came in and at which location it was dropped. You can then translate these location coordinates into corresponding document location (using RangeFromPoint() method of Window class) and do whatever you need to do with the dropped data. After this you simply hide your transparent window and everything goes back to normal.
A complete implementation of this approach along with source code is available in this excellent MSDN article.

Getting selected item in active window

I am using C# to develop an application that works with the clipboard, an was wondering if its possible to get the contents of what the user has selected in the current window, no matter what window it is (e.g. could be FireFox, notepad, etc.).
I'm not sure if you're going to be able to get a general solution for this problem. Take a look at this link;
http://www.eggheadcafe.com/software/aspnet/33899121/get-selected-text-of-active-window-.aspx
The author of this post reports that their solution works in Notepad, but not in Wordpad or Word. I don't know much about this area, but I would guess that this means there are various means through which text selection is implemented - even within Windows.
I think this also extends to Control-C, not just text selection. I believe that there are different ways of handling the copy command depending on the context in which it's used.
For example, if you press Control-C on a dialog box in Windows, it will copy the text without you have to select it manually.
Hopefully the link above is of some use to you. This seems like an interesting problem to overcome.
Edit:
Spoke too soon - just found this link;
http://social.msdn.microsoft.com/Forums/en/winformsapplications/thread/1dc356e6-9441-44de-9eda-247003fa6ef5
Looks like this is exactly what you're after - hope that works.
If something was only selected, it won't appear in the Clipboard. But if user copied some object that he had previously selected, then, yes, it will be in the Clipboard.

Categories