C#- triggering mouse and keyboard movements - c#

Is it possible to capture/trigger mouse or keyboard events inside an Internet Explorer browser tab?
How do I access the clipboard data of the browser?
How to manipulate the DOM of the page?
Does a mechanism exist which will work across all IE versions?

To capture you can use SetWindowsHookEx() with MouseProc() and KeyboardProc():
http://msdn.microsoft.com/en-us/library/ms644990
To trigger look at SendInput function():
http://msdn.microsoft.com/en-us/library/ms646310
You can access clipboard through Clipboard class, here some examples:
http://www.geekpedia.com/tutorial188_Clipboard-Copy-and-Paste-with-Csharp.html
http://www.codeproject.com/KB/shell/clipboard01.aspx
What do you mean 'manipulate'?
If you want to input some text, and press some buttons in IE window you can try to use UI Automation or Microsoft Active Accessiblity:
http://msdn.microsoft.com/en-us/library/ms788733.aspx

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 get the control of the UI Element Clicked in a external application

How can i get the control (and possibly its text value) of a control which was clicked in another third party application (its not a .net or wpf application for which there are answers which did not solve my problem)
I can get the click event in my app (using the global hooks as mentioned here) i want the control/handle of that particular UI Element
Example : I have opened Notepad and when i click on File Menu, i want the control of that File button.
Look at the documentation for SetWindowsHookEx using the WH_CALLWNDPROC param. This will let you intercept messages in Notepad window procedure. You'll need to figure out which messages get generated from clicking the menu items in Notepad, you can use Spy++ for that. But there is no real control for the File button, it is part of a menu.

Check to see if mouse is pressed anywhere on screen from silverlight control?

I have a silverlight control which acts as a drop down. I'd like to get a mouse pressed event when the mouse ISNT hovering over the dropdown control or any one of its children.
how can I go about doing that?
Well that depends on what you mean by "Screen".
With in Silverlight you are only going to be able to detect mouse down when the mouse is over the part of the screen that the Silverlight pluging is actually using.
The first step would be use this code:-
Application.Current.RootVisual.AddHandler(UIElement.MouseLeftButtonDown, myMouseButtonHandlerMethod, true)
This may well be enough for you, however, if you still need to detect mouse down when Popup or ChildWindow controls are in use you will need to attach this handler to those as well (since the sit above the RootVisual).
You may be able to take things further if you want to reach out into Javascript in the host html page. If your SL component only occupies a portion of the HTML Page presented you could get further events from via the HTMLBridge to detect mouse down anywhere in the browser client area.
If you really mean the whole screen then that isn't possible currently.

Right click, text capture

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.

RDP ActiveX Ctrl+Alt+Del

In our C# application we use the RDP viewer as an ActiveX control. The application has its own toolbar with a Ctrl+Alt+Del button. There does not seem to be a method on the ActiveX control to perform this function. I know you can hit Ctrl+Alt+End on your keyboard which is fine but how do I do that from the toolbar button click?
Try to use the SendKeys class.
In this example, you could send CTRL+ALT+END as this:
SendKeys.Send("(^%{END})");

Categories