C#: Record and Playback GUI Events - c#

how can i record and playback mouse and keybaord events.
i need this to capture the user interactions with my application so that later on i can play to see what user did.

There are literally hundreds of keyboard / mouse automation apps out there:
http://www.nonags.com/nonags/auto.html
I recommend Do It Again - its free, easy to use and works well, although if I remember correctly it has a quirk where it doesn't work particularly well over a remote desktop connection.
UPDATE: Just re-read the question, I dont think what you want is the ability to record keyboard / mouse actions, as its not guarenteed that the application will "keep up" with the mouse clicks (windows could open in slightly different places, or there could be a slight delay etc...)
What you want is some screen capture software.

You should hook keyboard and mouse events, see Processing Global Mouse and Keyboard Hooks in C# , Low-Level Mouse Hook in C# or Processing Global Windows Mouse and Keyboard Hooks in C#

Related

sharing mouse click and key press events through windows (or handles)

I have 3, and sometimes more duplicates of an executable, and what I would like to do is to reduce workforce by sharing mouse click and key press events through all applications, with C#.
I am able to get handle's of executables, so ideas might be based on acquired handles.
Also I have done some work to ease my work, all applications are arranged at same coordinates, with the same window size. So basically transparent mouse and key clicks which will interact with all windows (the top window, as well as background windows) would do the trick.
You need to sned Windows Messages from one application to the other, but that involves security configuration.
Here you have how to do it:
Communication between applications via Windows Messages
Here you have comments about security issues, and ideas for alternative solutions
Sending, receiving and processing a windows message between windows applications
Stacking the windows isn't necessary. Once you have the handle to all the windows that you want to interact with, P/Invoke the SendMessage API to send your click to each window at it's target coordinates.
If I had the need for such a thing, I would put a picture box on a form and capture the image of one of the windows (so I can see what I'm clicking), then process the PictureBox.Click event to calculate the coordinates to use in the P/Invoke call(s).
There are several other tricks you could use to make your life easier and click-sharing utility better, but this will get you started.

How to simulate Keystrokes in C#?

Google gives this but it seems to only work for a WindowsForms class. I'm completely new to C#. What I'm trying to make is a program that monitors for an event, and then (for example), acts as if the 'H' key has been pressed. I don't really want to worry about what the active window is or anything, or sending a keystroke to an application, I just want the program to act as if I have physically pressed the 'H' button on my keyboard. The SendKeys class doesn't seem to work in a general class. Am I going about this completely the wrong way?
From How to: Simulate Mouse and Keyboard Events in Code:
Windows Forms provides several options for programmatically simulating mouse and keyboard input.
Simulating Mouse Input
The best way to simulate mouse events is to call the OnEventName method that raises the mouse event you want to simulate.
Simulating Keyboard Input
Although you can simulate keyboard input by using the strategies discussed above for mouse input, Windows Forms also provides the SendKeys class for sending keystrokes to the active application.

Capture all Windows 7 Touch events, not just on my form when it has focus

I have an application which has a form, but the fact that it has a form is irrelevant.
With this app, I need to listen to all Operating System level Touch events. Basically I need to capture that the screen has been touched no matter which form has focus, gather all the info like coordinates etc. and then do whatever with it.
I'll actually be sending it on to another app via a Windows Message but that's not relevant either. I just need to know how to listen and capture ALL OS level touch + drag events etc.
You can read HID data directly, using a Raw Input API and to parse it by yourself.
In general:
Find Hids and store preparsed data.
Register for input events
On WM_INPUT event parse buffer using HID API functions and preparsed data.
This link explains the topic of keyboard/mouse event hooks.
It is a rather advanced subject however, filled with lots of low-level interop. I'd avoid such a task and try to come up with a different solution for this. What is your final goal with this application?

Capturing mouse/keyboard events outside of form (app running in background)

I have an app that runs in the background (minimized/task tray). I need to be able to detect mouse activity (clicks, move) as well as keyboard activity.
What is the best way to do this given the constraint that my window is not "focused" ?
Take a look at this library globalmousekeyhook.
It is 100% managed c# code to install global mouse and keyboard hooks.
It wraps low level hooks into common windows forms keyboard and mouse events.
The magic words are windows hooks. These are created with a p/invoke call to SetWindowsHookEx. You can set up a hook to monitor, among others, keyboard and mouse events. Normally, such hooks are local to the application, but you can also create global hooks. The Microsoft KB shows how.
However, be aware that not all types of global hooks can be used from .NET. In particular, there are only two that you can use: the low-level keyboard and mouse hooks, known as WH_KEYBOARD_LL and WH_MOUSE_LL. Luckily, these are just what you need.

Emulate Key Presses On an App that takes no Win Messages

I want to send an Application Key Presses, To Automate some stuff that has to be done repeatedly and So I don't always have to cramp my fingers.
In C#, it's nice to use SendKeys.Send(), but this won't work because the Application doesn't take Windows Messages. SendKeys.SendWait() does nothing at all.
How would I STILL Simulate the Keyboard events?
Come To Think of It, I was going to use some P/Invoke to simulate Mouse Events too, but If it takes no messages, How Can I get around that?
EDIT - I can use mouse and keyboard to interact with the program, I just cannot manipulate it with Windows Messages sent from my own Code.
Have you tried AutoIt?
Is it a console app? If so, maybe you should be SendKeys'ing to the command shell instance it is running in.

Categories

Resources