├── .gitignore ├── LICENSE ├── README.md ├── SimExamples ├── App.config ├── App.xaml ├── App.xaml.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings └── SimExamples.csproj ├── SimWinGamePad ├── GamePadControl.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ └── SimWinGamePad.nuspec ├── ScpBus.cs ├── ScpDriverInstaller.cs ├── ScpDriverInstaller.exe ├── SimGamePad.cs ├── SimWinGamePad.csproj ├── SimulatedGamePadState.cs ├── UserDeclinedDriverException.cs └── XnaInputToScpBusReport.cs ├── SimWinInput.sln ├── SimWinKeyboard ├── InteropKeyboard.cs ├── Properties │ ├── AssemblyInfo.cs │ └── SimWinKeyboard.nuspec ├── SimKeyboard.cs └── SimWinKeyboard.csproj ├── SimWinMouse ├── InteropMouse.cs ├── InteropScreen.cs ├── Properties │ ├── AssemblyInfo.cs │ └── SimWinMouse.nuspec ├── ScreenSize.cs ├── SimMouse.cs └── SimWinMouse.csproj └── packages └── nuget.exe /.gitignore: -------------------------------------------------------------------------------- 1 | *.suo 2 | *.user 3 | *.cache 4 | [Bb]in/ 5 | [Oo]bj/ 6 | /packages/ 7 | .vs 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 David Rieman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SimWinInput 2 | Simulate mouse, keyboard, and GamePad events on Windows. 3 | These provide convenient, small, easy-to-use APIs so you don't have to muck around in messy interop directly. 4 | 5 | Purpose: Accessibility, automation, augmented gaming, and more. 6 | 7 | 8 | ## Simulate Mouse 9 | NOTE: The modern .NET `System.Windows.Forms.Cursor` provides an effective means to control the mouse cursor position by setting the `Cursor.Position` property. If mouse _positioning_ is all that you need, try `Cursor.Position` first. However, `SimWinMouse` will help you accomplish additional scenarios, such as clicking. 10 | 11 | Install `SimWinMouse` [via NuGet](https://docs.microsoft.com/en-us/nuget/quickstart/use-a-package) 12 | or pull the source and add a project reference. 13 | 14 | To immediately move the mouse to the pixel at (100,50) and left-click: 15 | ``` 16 | SimMouse.Click(MouseButtons.Left, 100, 50); 17 | ``` 18 | 19 | To click and drag from (20, 20) to (50, 50): 20 | ``` 21 | SimMouse.Act(SimMouse.Action.LeftButtonDown, 20, 20); 22 | Thread.Sleep(10); 23 | SimMouse.Act(SimMouse.Action.LeftButtonUp, 50, 50); 24 | ``` 25 | 26 | ### Advanced Mouse Simulation 27 | If you have more advanced scenarios than the simple API above supports, check out the `InteropMouse.mouse_event` DLL import. 28 | 29 | 30 | ## Simulate Keyboard 31 | Install `SimWinKeyboard` [via NuGet](https://docs.microsoft.com/en-us/nuget/quickstart/use-a-package) 32 | or pull the source and add a project reference. 33 | 34 | To simulate a 'Q' keystroke: 35 | ``` 36 | SimKeyboard.Press((byte)'Q'); 37 | ``` 38 | 39 | To hold the 'Q' key for a prolonged time until later releasing it: 40 | ``` 41 | SimKeyboard.KeyDown((byte)'Q'); 42 | ... 43 | SimKeyboard.KeyUp((byte)'Q'); 44 | ``` 45 | 46 | ### Advanced Keyboard Simulation 47 | If you have more advanced scenarios than the simple API above supports, check out the `InteropKeyboard.keybd_event` DLL import. 48 | 49 | 50 | ## Simulate GamePad 51 | Install `SimWinGamePad` [via NuGet](https://docs.microsoft.com/en-us/nuget/quickstart/use-a-package) 52 | or pull the source and add a project reference. 53 | 54 | Before issuing other commands, call `SimGamePad.Instance.Initialize()`. 55 | 56 | Upon first initialization on a given PC, the user may be prompted to accept automatic installation of the [ScpVBus](https://github.com/nefarius/ScpVBus) driver required to simulate Xbox 360 GamePads attached to Windows. 57 | (This is accomplished via the [ScpDriverInterface](https://github.com/DavidRieman/ScpDriverInterface/) installer, which is now an embedded resource in SimWinInput and extracted at runtime as needed. Thus you no longer need to explicitly include the installer executable with your own application/installers.) 58 | Recovery from missing driver requires neither reboot nor app restart, but Initialize will throw an exception if something prevents success (such as the user declining the prompt or UAC elevation for the installer). 59 | 60 | There can be up to four simulated GamePads, but they do not start plugged in. To plug one in as the first GamePad: 61 | ``` 62 | SimGamePad.Instance.PlugIn(); 63 | ``` 64 | 65 | Then, to simulate pressing the 'A' button on the GamePad for a moment, before releasing it: 66 | ``` 67 | SimGamePad.Instance.Use(GamePadControl.A); 68 | ``` 69 | 70 | Even the analog controls can be simulated into maximum state for a moment, before returning them to their default, unheld positions: 71 | ``` 72 | // Pull and release the left trigger. 73 | SimGamePad.Instance.Use(GamePadControl.LeftTrigger); 74 | // Move the right analog stick into the leftmost position, then return to neutral position. 75 | SimGamePad.Instance.Use(GamePadControl.RightStickLeft); 76 | ``` 77 | 78 | To unplug the virtual GamePad: 79 | ``` 80 | SimGamePad.Instance.Unplug(); 81 | ``` 82 | 83 | When exiting the program, you should always call `SimGamePad.Instance.ShutDown()`. 84 | This will unplug any remaining simulated GamePads and clean up any utilized resources, such as disposing the driver. 85 | 86 | ### Intermediate GamePad Simulation 87 | Should you need more than one GamePad simulated, each command can optionally specify an index from 0 to 3 for which one to drive. You can also specify hold times (in milliseconds) if the default is not suitable for your needs: 88 | ``` 89 | SimGamePad.Instance.Use(GamePadControl.LeftTrigger, 2, 500); 90 | ``` 91 | 92 | You can use GamePadControl as flags to designate multiple controls to use at the same time. 93 | You can also simulate controls in a held position until later asking to release them. 94 | This example demonstrates both: 95 | ``` 96 | SimGamePad.Instance.SetControl(GamePadControl.RightTrigger | GamePadControl.RightBumper); 97 | ... 98 | SimGamePad.Instance.ReleaseControl(GamePadControl.RightTrigger | GamePadControl.RightBumper); 99 | ``` 100 | 101 | 102 | ### Advanced GamePad Simulation 103 | For more advanced scenarios, you can exercise full control over all analog controls and buttons, including the guide button, by modifying and managing state updates manually. For example: 104 | ``` 105 | // Get a reference to the state of the first GamePad: 106 | var simPad = SimGamePad.Instance; 107 | var state = simPad.State[0]; 108 | // Pull the left trigger halfway back: 109 | state.LeftTrigger = 127; 110 | // Move the right analog stick three quarters of the way to the left: 111 | state.RightStickX = short.MinValue * 3 / 4; 112 | // Add the RightBumber to the set of held buttons: 113 | state.Buttons |= GamePadControl.RightShoulder; 114 | // Update the driver's simulated state with the above state changes: 115 | simPad.Update(0); 116 | ... 117 | // Reset the GamePad to the natural at-rest state: 118 | state.Reset(); 119 | simPad.Update(); 120 | ``` 121 | -------------------------------------------------------------------------------- /SimExamples/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /SimExamples/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /SimExamples/App.xaml.cs: -------------------------------------------------------------------------------- 1 | // This file is part of the SimWinInput project, which is released under MIT License. 2 | // For details, see: https://github.com/DavidRieman/SimWinInput 3 | 4 | namespace SimExamples 5 | { 6 | using System.Windows; 7 | 8 | /// Interaction logic for App.xaml 9 | public partial class App : Application 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /SimExamples/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 |