1

I need to simulate mouse clicks/touchscreen presses and key presses in Windows 8.1 (.NET 4.5, WPF). This is for crude unattended automation for certain processes/applications (all external to the application I am developing) whereby there is nothing exposed to allow me to do it any other way.

A few years ago in .NET 2.0 and WinForms I did something similar using the SendInput API.

Is that still the de-facto method to achieve this in .NET 4.5 and WPF, or is there something newer that has come along, or maybe even a WPF wrapper for SendInput?

Cheetah
  • 13,785
  • 31
  • 106
  • 190
  • Take a look at the [C# Simulate Key Press](http://stackoverflow.com/questions/7307868/c-sharp-simulate-key-press) post. If that doesn't help, please take a look at the [Windows Input Simulator (C# SendInput Wrapper - Simulate Keyboard and Mouse)](http://inputsimulator.codeplex.com/) project on CodePlex. My final offering is the [How to: Simulate Mouse and Keyboard Events in Code](http://msdn.microsoft.com/en-us/library/vstudio/ms171548(v=vs.100).aspx) page from MSDN, which uses the `SendKeys` class to do what you want. – Sheridan Jan 30 '14 at 13:59

2 Answers2

1

This kind of automation could be done Microsoft's UI Automation framework. For better understanding have a look at http://msdn.microsoft.com/en-us/library/ms747327(v=vs.110).aspx

A also nice introduction can be found at http://blog.functionalfun.net/2009/06/introduction-to-ui-automation-with.html

  • Would this work with absolutely ANY application? As an example. Would this work to simulate a mouse click on a flash application running in an browser? – Cheetah Jan 30 '14 at 11:39
  • I don't think that this would work. For a situation like this I would give Selenium with flash-selenium extension closer look. – fschaeffler Jan 30 '14 at 11:45
  • Selenium is for web browsers IIRC. I am looking for a one-size-fits-all solution. Currently that is `SendInput`. Thanks for the responses so far! – Cheetah Jan 30 '14 at 11:51
1

I had to do this just the other day to automate the process of waking a machine up from sleep mode, mouse_event seems to still work fine in Win8. Haven't tried the key events, but I don't see why they wouldn't work also. There's some functional interop code here.

Community
  • 1
  • 1
Mark Feldman
  • 15,731
  • 3
  • 31
  • 58