├── .nuget
├── NuGet.exe
├── NuGet.Config
└── NuGet.targets
├── WindowsInput
├── WindowsInput.snk
├── MouseButton.cs
├── Native
│ ├── XButton.cs
│ ├── InputType.cs
│ ├── HARDWAREINPUT.cs
│ ├── MOUSEKEYBDHARDWAREINPUT.cs
│ ├── KeyboardFlag.cs
│ ├── INPUT.cs
│ ├── MouseFlag.cs
│ ├── KEYBDINPUT.cs
│ ├── MOUSEINPUT.cs
│ ├── NativeMethods.cs
│ └── VirtualKeyCode.cs
├── IInputMessageDispatcher.cs
├── WindowsInput.nuspec
├── IInputSimulator.cs
├── WindowsInputMessageDispatcher.cs
├── Properties
│ └── AssemblyInfo.cs
├── IInputDeviceStateAdaptor.cs
├── InputSimulator.cs
├── WindowsInput.csproj
├── IKeyboardSimulator.cs
├── IMouseSimulator.cs
├── KeyboardSimulator.cs
├── WindowsInputDeviceStateAdaptor.cs
├── MouseSimulator.cs
└── InputBuilder.cs
├── WindowsInput.Tests
├── WindowsInput.Tests.snk
├── packages.config
├── InputBuilderTests.cs
├── UnicodeText
│ ├── UnicodeTestForm.cs
│ ├── UnicodeRange.cs
│ ├── UnicodeTestForm.Designer.cs
│ ├── UnicodeTestForm.resx
│ └── UnicodeTextTests.cs
├── Properties
│ └── AssemblyInfo.cs
├── InputSimulatorExamples.cs
└── WindowsInput.Tests.csproj
├── WindowsInput.SampleClient.Wpf
├── Properties
│ ├── Settings.settings
│ ├── Settings.Designer.cs
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ └── Resources.resx
├── MainWindow.xaml
├── App.xaml
├── App.xaml.cs
├── MainWindow.xaml.cs
└── WindowsInput.SampleClient.Wpf.csproj
├── .gitignore
├── LICENSE
├── WindowsInput.sln
├── README.md
└── BuildProcessTemplates
└── UpgradeTemplate.xaml
/.nuget/NuGet.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/michaelnoonan/inputsimulator/HEAD/.nuget/NuGet.exe
--------------------------------------------------------------------------------
/WindowsInput/WindowsInput.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/michaelnoonan/inputsimulator/HEAD/WindowsInput/WindowsInput.snk
--------------------------------------------------------------------------------
/WindowsInput.Tests/WindowsInput.Tests.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/michaelnoonan/inputsimulator/HEAD/WindowsInput.Tests/WindowsInput.Tests.snk
--------------------------------------------------------------------------------
/.nuget/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/WindowsInput.Tests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/WindowsInput.SampleClient.Wpf/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/WindowsInput.SampleClient.Wpf/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/WindowsInput.SampleClient.Wpf/App.xaml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/WindowsInput.SampleClient.Wpf/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Windows;
7 |
8 | namespace InputSimulator.SampleClient.Wpf
9 | {
10 | ///
11 | /// Interaction logic for App.xaml
12 | ///
13 | public partial class App : Application
14 | {
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/WindowsInput/MouseButton.cs:
--------------------------------------------------------------------------------
1 | namespace WindowsInput
2 | {
3 | ///
4 | /// The mouse button
5 | ///
6 | public enum MouseButton
7 | {
8 | ///
9 | /// Left mouse button
10 | ///
11 | LeftButton,
12 |
13 | ///
14 | /// Middle mouse button
15 | ///
16 | MiddleButton,
17 |
18 | ///
19 | /// Right moust button
20 | ///
21 | RightButton,
22 | }
23 | }
--------------------------------------------------------------------------------
/WindowsInput/Native/XButton.cs:
--------------------------------------------------------------------------------
1 | namespace WindowsInput.Native
2 | {
3 | ///
4 | /// XButton definitions for use in the MouseData property of the structure. (See: http://msdn.microsoft.com/en-us/library/ms646273(VS.85).aspx)
5 | ///
6 | internal enum XButton : uint
7 | {
8 | ///
9 | /// Set if the first X button is pressed or released.
10 | ///
11 | XButton1 = 0x0001,
12 |
13 | ///
14 | /// Set if the second X button is pressed or released.
15 | ///
16 | XButton2 = 0x0002,
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/WindowsInput.Tests/InputBuilderTests.cs:
--------------------------------------------------------------------------------
1 | using System.Linq;
2 | using NUnit.Framework;
3 | using WindowsInput.Native;
4 |
5 | namespace WindowsInput.Tests
6 | {
7 | [TestFixture]
8 | public class InputBuilderTests
9 | {
10 | [Test]
11 | public void AddKeyDown()
12 | {
13 | var builder = new InputBuilder();
14 | Assert.That(builder.ToArray(), Is.Empty);
15 | builder.AddKeyDown(VirtualKeyCode.VK_A);
16 | Assert.That(builder.Count(), Is.EqualTo(1));
17 | Assert.That(builder[0].Type, Is.EqualTo((uint)InputType.Keyboard));
18 | Assert.That(builder[0].Data.Keyboard.KeyCode, Is.EqualTo((ushort)VirtualKeyCode.VK_A));
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/WindowsInput.Tests/UnicodeText/UnicodeTestForm.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | namespace WindowsInput.Tests.UnicodeText
5 | {
6 | public partial class UnicodeTestForm : Form
7 | {
8 | public UnicodeTestForm()
9 | {
10 | InitializeComponent();
11 | }
12 |
13 | public string Expected
14 | {
15 | get { return ExpectedTextBox.Text; }
16 | set { ExpectedTextBox.Text = value; }
17 | }
18 |
19 | public string Recieved { get { return RecievedTextBox.Text; } }
20 |
21 | protected override void OnLoad(EventArgs e)
22 | {
23 | base.OnLoad(e);
24 | RecievedTextBox.Focus();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/WindowsInput.SampleClient.Wpf/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Windows;
6 | using System.Windows.Controls;
7 | using System.Windows.Data;
8 | using System.Windows.Documents;
9 | using System.Windows.Input;
10 | using System.Windows.Media;
11 | using System.Windows.Media.Imaging;
12 | using System.Windows.Navigation;
13 | using System.Windows.Shapes;
14 |
15 | namespace InputSimulator.SampleClient.Wpf
16 | {
17 | ///
18 | /// Interaction logic for MainWindow.xaml
19 | ///
20 | public partial class MainWindow : Window
21 | {
22 | public MainWindow()
23 | {
24 | InitializeComponent();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/WindowsInput/Native/InputType.cs:
--------------------------------------------------------------------------------
1 | namespace WindowsInput.Native
2 | {
3 | ///
4 | /// Specifies the type of the input event. This member can be one of the following values.
5 | ///
6 | internal enum InputType : uint // UInt32
7 | {
8 | ///
9 | /// INPUT_MOUSE = 0x00 (The event is a mouse event. Use the mi structure of the union.)
10 | ///
11 | Mouse = 0,
12 |
13 | ///
14 | /// INPUT_KEYBOARD = 0x01 (The event is a keyboard event. Use the ki structure of the union.)
15 | ///
16 | Keyboard = 1,
17 |
18 | ///
19 | /// INPUT_HARDWARE = 0x02 (Windows 95/98/Me: The event is from input hardware other than a keyboard or mouse. Use the hi structure of the union.)
20 | ///
21 | Hardware = 2,
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #OS junk files
2 | [Tt]humbs.db
3 | *.DS_Store
4 |
5 | #Visual Studio files
6 | *.[Oo]bj
7 | *.user
8 | *.aps
9 | *.pch
10 | *.vspscc
11 | *.vssscc
12 | *_i.c
13 | *_p.c
14 | *.ncb
15 | *.suo
16 | *.tlb
17 | *.tlh
18 | *.bak
19 | *.[Cc]ache
20 | *.ilk
21 | *.log
22 | *.lib
23 | *.sbr
24 | *.sdf
25 | *.opensdf
26 | *.unsuccessfulbuild
27 | ipch/
28 | obj/
29 | [Bb]in
30 | [Dd]ebug*/
31 | [Rr]elease*/
32 | Ankh.NoLoad
33 |
34 | #MonoDevelop
35 | *.pidb
36 | *.userprefs
37 |
38 | #Tooling
39 | _ReSharper*/
40 | *.resharper
41 | [Tt]est[Rr]esult*
42 | *.sass-cache
43 |
44 | #Project files
45 | [Bb]uild/
46 |
47 | #Subversion files
48 | .svn
49 |
50 | # Office Temp Files
51 | ~$*
52 |
53 | #NuGet
54 | packages/
55 |
56 | #ncrunch
57 | *ncrunch*
58 | *crunch*.local.xml
59 |
60 | # visual studio database projects
61 | *.dbmdl
62 |
63 | #Test files
64 | *.testsettings
65 |
--------------------------------------------------------------------------------
/WindowsInput.Tests/UnicodeText/UnicodeRange.cs:
--------------------------------------------------------------------------------
1 | using System.Text;
2 |
3 | namespace WindowsInput.Tests.UnicodeText
4 | {
5 | public class UnicodeRange
6 | {
7 | public string Name { get; set; }
8 | public int Low { get; set; }
9 | public int High { get; set; }
10 |
11 | public string Characters
12 | {
13 | get
14 | {
15 | var i = Low;
16 | var sb = new StringBuilder(High - Low + 10);
17 | while (i <= High)
18 | {
19 | sb.Append(char.ConvertFromUtf32(i));
20 | i++;
21 | }
22 | return sb.ToString();
23 | }
24 | }
25 |
26 | public UnicodeRange(string name, int low, int high)
27 | {
28 | Name = name;
29 | Low = low;
30 | High = high;
31 | }
32 | }
33 | }
--------------------------------------------------------------------------------
/WindowsInput/IInputMessageDispatcher.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using WindowsInput.Native;
3 |
4 | namespace WindowsInput
5 | {
6 | ///
7 | /// The contract for a service that dispatches messages to the appropriate destination.
8 | ///
9 | internal interface IInputMessageDispatcher
10 | {
11 | ///
12 | /// Dispatches the specified list of messages in their specified order.
13 | ///
14 | /// The list of messages to be dispatched.
15 | /// If the array is empty.
16 | /// If the array is null.
17 | /// If the any of the commands in the array could not be sent successfully.
18 | void DispatchInput(INPUT[] inputs);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/WindowsInput/Native/HARDWAREINPUT.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace WindowsInput.Native
4 | {
5 | #pragma warning disable 649
6 | ///
7 | /// The HARDWAREINPUT structure contains information about a simulated message generated by an input device other than a keyboard or mouse. (see: http://msdn.microsoft.com/en-us/library/ms646269(VS.85).aspx)
8 | /// Declared in Winuser.h, include Windows.h
9 | ///
10 | internal struct HARDWAREINPUT
11 | {
12 | ///
13 | /// Value specifying the message generated by the input hardware.
14 | ///
15 | public UInt32 Msg;
16 |
17 | ///
18 | /// Specifies the low-order word of the lParam parameter for uMsg.
19 | ///
20 | public UInt16 ParamL;
21 |
22 | ///
23 | /// Specifies the high-order word of the lParam parameter for uMsg.
24 | ///
25 | public UInt16 ParamH;
26 | }
27 | #pragma warning restore 649
28 | }
29 |
--------------------------------------------------------------------------------
/WindowsInput/WindowsInput.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | InputSimulator
5 | 0.2.0.0
6 | Windows Input Simulator
7 | Michael Noonan
8 | Michael Noonan
9 | http://inputsimulator.codeplex.com/license
10 | http://inputsimulator.codeplex.com
11 | false
12 | The Windows Input Simulator provides a simple .NET (C#) interface to simulate Keyboard or Mouse input using the Win32 SendInput method. All of the Interop is done for you and there's a simple programming model for sending multiple keystrokes.
13 | This version introduces more comprehensive Unicode tests and support for Mouse Simulation.
14 | Copyright 2009-2013
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/WindowsInput/Native/MOUSEKEYBDHARDWAREINPUT.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 |
3 | namespace WindowsInput.Native
4 | {
5 | #pragma warning disable 649
6 | ///
7 | /// The combined/overlayed structure that includes Mouse, Keyboard and Hardware Input message data (see: http://msdn.microsoft.com/en-us/library/ms646270(VS.85).aspx)
8 | ///
9 | [StructLayout(LayoutKind.Explicit)]
10 | internal struct MOUSEKEYBDHARDWAREINPUT
11 | {
12 | ///
13 | /// The definition.
14 | ///
15 | [FieldOffset(0)]
16 | public MOUSEINPUT Mouse;
17 |
18 | ///
19 | /// The definition.
20 | ///
21 | [FieldOffset(0)]
22 | public KEYBDINPUT Keyboard;
23 |
24 | ///
25 | /// The definition.
26 | ///
27 | [FieldOffset(0)]
28 | public HARDWAREINPUT Hardware;
29 | }
30 | #pragma warning restore 649
31 | }
32 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Michael Noonan
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 |
--------------------------------------------------------------------------------
/WindowsInput/IInputSimulator.cs:
--------------------------------------------------------------------------------
1 | namespace WindowsInput
2 | {
3 | ///
4 | /// The contract for a service that simulates Keyboard and Mouse input and Hardware Input Device state detection for the Windows Platform.
5 | ///
6 | public interface IInputSimulator
7 | {
8 | ///
9 | /// Gets the instance for simulating Keyboard input.
10 | ///
11 | /// The instance.
12 | IKeyboardSimulator Keyboard { get; }
13 |
14 | ///
15 | /// Gets the instance for simulating Mouse input.
16 | ///
17 | /// The instance.
18 | IMouseSimulator Mouse { get; }
19 |
20 | ///
21 | /// Gets the instance for determining the state of the various input devices.
22 | ///
23 | /// The instance.
24 | IInputDeviceStateAdaptor InputDeviceState { get; }
25 | }
26 | }
--------------------------------------------------------------------------------
/WindowsInput.SampleClient.Wpf/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30128.1
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace InputSimulator.SampleClient.Wpf.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/WindowsInput/Native/KeyboardFlag.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace WindowsInput.Native
4 | {
5 | ///
6 | /// Specifies various aspects of a keystroke. This member can be certain combinations of the following values.
7 | ///
8 | [Flags]
9 | internal enum KeyboardFlag : uint // UInt32
10 | {
11 | ///
12 | /// KEYEVENTF_EXTENDEDKEY = 0x0001 (If specified, the scan code was preceded by a prefix byte that has the value 0xE0 (224).)
13 | ///
14 | ExtendedKey = 0x0001,
15 |
16 | ///
17 | /// KEYEVENTF_KEYUP = 0x0002 (If specified, the key is being released. If not specified, the key is being pressed.)
18 | ///
19 | KeyUp = 0x0002,
20 |
21 | ///
22 | /// KEYEVENTF_UNICODE = 0x0004 (If specified, wScan identifies the key and wVk is ignored.)
23 | ///
24 | Unicode = 0x0004,
25 |
26 | ///
27 | /// KEYEVENTF_SCANCODE = 0x0008 (Windows 2000/XP: If specified, the system synthesizes a VK_PACKET keystroke. The wVk parameter must be zero. This flag can only be combined with the KEYEVENTF_KEYUP flag. For more information, see the Remarks section.)
28 | ///
29 | ScanCode = 0x0008,
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/WindowsInput.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("WindowsInput.UnitTests")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("Microsoft")]
12 | [assembly: AssemblyProduct("WindowsInput.UnitTests")]
13 | [assembly: AssemblyCopyright("Copyright © michaelnoonan 2010")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("9e1ff335-ed74-4135-92cf-5e4cf1d38344")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("0.2.0.0")]
36 | [assembly: AssemblyFileVersion("0.2.0.0")]
37 |
--------------------------------------------------------------------------------
/WindowsInput/Native/INPUT.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace WindowsInput.Native
4 | {
5 | #pragma warning disable 649
6 | ///
7 | /// The INPUT structure is used by SendInput to store information for synthesizing input events such as keystrokes, mouse movement, and mouse clicks. (see: http://msdn.microsoft.com/en-us/library/ms646270(VS.85).aspx)
8 | /// Declared in Winuser.h, include Windows.h
9 | ///
10 | ///
11 | /// This structure contains information identical to that used in the parameter list of the keybd_event or mouse_event function.
12 | /// Windows 2000/XP: INPUT_KEYBOARD supports nonkeyboard input methods, such as handwriting recognition or voice recognition, as if it were text input by using the KEYEVENTF_UNICODE flag. For more information, see the remarks section of KEYBDINPUT.
13 | ///
14 | internal struct INPUT
15 | {
16 | ///
17 | /// Specifies the type of the input event. This member can be one of the following values.
18 | /// - The event is a mouse event. Use the mi structure of the union.
19 | /// - The event is a keyboard event. Use the ki structure of the union.
20 | /// - Windows 95/98/Me: The event is from input hardware other than a keyboard or mouse. Use the hi structure of the union.
21 | ///
22 | public UInt32 Type;
23 |
24 | ///
25 | /// The data structure that contains information about the simulated Mouse, Keyboard or Hardware event.
26 | ///
27 | public MOUSEKEYBDHARDWAREINPUT Data;
28 | }
29 | #pragma warning restore 649
30 | }
31 |
--------------------------------------------------------------------------------
/WindowsInput.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsInput", "WindowsInput\WindowsInput.csproj", "{3549CD6F-80F8-450F-B99E-CF0A736B1F2A}"
5 | EndProject
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsInput.Tests", "WindowsInput.Tests\WindowsInput.Tests.csproj", "{93982D2F-BEAD-49F7-86A9-C68159410F28}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{C2945350-728A-4D62-93D6-FA5F5015A7C6}"
9 | ProjectSection(SolutionItems) = preProject
10 | .nuget\NuGet.Config = .nuget\NuGet.Config
11 | .nuget\NuGet.exe = .nuget\NuGet.exe
12 | .nuget\NuGet.targets = .nuget\NuGet.targets
13 | EndProjectSection
14 | EndProject
15 | Global
16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
17 | Debug|Any CPU = Debug|Any CPU
18 | Release|Any CPU = Release|Any CPU
19 | EndGlobalSection
20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
21 | {3549CD6F-80F8-450F-B99E-CF0A736B1F2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22 | {3549CD6F-80F8-450F-B99E-CF0A736B1F2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
23 | {3549CD6F-80F8-450F-B99E-CF0A736B1F2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
24 | {3549CD6F-80F8-450F-B99E-CF0A736B1F2A}.Release|Any CPU.Build.0 = Release|Any CPU
25 | {93982D2F-BEAD-49F7-86A9-C68159410F28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26 | {93982D2F-BEAD-49F7-86A9-C68159410F28}.Debug|Any CPU.Build.0 = Debug|Any CPU
27 | {93982D2F-BEAD-49F7-86A9-C68159410F28}.Release|Any CPU.ActiveCfg = Release|Any CPU
28 | {93982D2F-BEAD-49F7-86A9-C68159410F28}.Release|Any CPU.Build.0 = Release|Any CPU
29 | EndGlobalSection
30 | GlobalSection(SolutionProperties) = preSolution
31 | HideSolutionNode = FALSE
32 | EndGlobalSection
33 | EndGlobal
34 |
--------------------------------------------------------------------------------
/WindowsInput/WindowsInputMessageDispatcher.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 | using WindowsInput.Native;
4 |
5 | namespace WindowsInput
6 | {
7 | ///
8 | /// Implements the by calling .
9 | ///
10 | internal class WindowsInputMessageDispatcher : IInputMessageDispatcher
11 | {
12 | ///
13 | /// Dispatches the specified list of messages in their specified order by issuing a single called to .
14 | ///
15 | /// The list of messages to be dispatched.
16 | /// If the array is empty.
17 | /// If the array is null.
18 | /// If the any of the commands in the array could not be sent successfully.
19 | public void DispatchInput(INPUT[] inputs)
20 | {
21 | if (inputs == null) throw new ArgumentNullException("inputs");
22 | if (inputs.Length == 0) throw new ArgumentException("The input array was empty", "inputs");
23 | var successful = NativeMethods.SendInput((UInt32)inputs.Length, inputs, Marshal.SizeOf(typeof (INPUT)));
24 | if (successful != inputs.Length)
25 | throw new Exception("Some simulated input commands were not sent successfully. The most common reason for this happening are the security features of Windows including User Interface Privacy Isolation (UIPI). Your application can only send commands to applications of the same or lower elevation. Similarly certain commands are restricted to Accessibility/UIAutomation applications. Refer to the project home page and the code samples for more information.");
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/WindowsInput/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle("WindowsInput")]
10 | [assembly: AssemblyDescription("Provides a useful wrapper around the User32 SendInput and related native Windows functions for simulating Input Devices in Windows including Keyboard and Mouse.")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("michaelnoonan")]
13 | [assembly: AssemblyProduct("WindowsInput")]
14 | [assembly: AssemblyCopyright("Copyright © michaelnoonan 2010")]
15 | [assembly: AssemblyTrademark("")]
16 | [assembly: AssemblyCulture("")]
17 | [assembly: CLSCompliant(true)]
18 | [assembly: InternalsVisibleTo("WindowsInput.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100737a78808b105748ff1251c1eb68752c2eb02dea580cade31d04fbc4081d7f420c639de2f3081461f734d48499c50133adb9dab02d828031cdec7d2941652233aefadf961658f948c13d43da9860d76ded6e959eebec0ddae03cc67dabf1aa83973602690e228c5b2d9434e62760d325d4c46a1fdf71971bb7a22f0de55b7bf0")]
19 |
20 | // Setting ComVisible to false makes the types in this assembly not visible
21 | // to COM components. If you need to access a type in this assembly from
22 | // COM, set the ComVisible attribute to true on that type.
23 | [assembly: ComVisible(false)]
24 |
25 | // The following GUID is for the ID of the typelib if this project is exposed to COM
26 | [assembly: Guid("25871eb0-27d6-42da-a3fe-cb60eb01f15a")]
27 |
28 | // Version information for an assembly consists of the following four values:
29 | //
30 | // Major Version
31 | // Minor Version
32 | // Build Number
33 | // Revision
34 | //
35 | // You can specify all the values or you can default the Build and Revision Numbers
36 | // by using the '*' as shown below:
37 | // [assembly: AssemblyVersion("1.0.*")]
38 | [assembly: AssemblyVersion("0.2.0.0")]
39 | [assembly: AssemblyFileVersion("0.2.0.0")]
40 |
--------------------------------------------------------------------------------
/WindowsInput.SampleClient.Wpf/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("InputSimulator.SampleClient.Wpf")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("Microsoft")]
14 | [assembly: AssemblyProduct("InputSimulator.SampleClient.Wpf")]
15 | [assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/WindowsInput/IInputDeviceStateAdaptor.cs:
--------------------------------------------------------------------------------
1 | using WindowsInput.Native;
2 |
3 | namespace WindowsInput
4 | {
5 | ///
6 | /// The contract for a service that interprets the state of input devices.
7 | ///
8 | public interface IInputDeviceStateAdaptor
9 | {
10 | ///
11 | /// Determines whether the specified key is up or down.
12 | ///
13 | /// The for the key.
14 | ///
15 | /// true if the key is down; otherwise, false.
16 | ///
17 | bool IsKeyDown(VirtualKeyCode keyCode);
18 |
19 | ///
20 | /// Determines whether the specified key is up or down.
21 | ///
22 | /// The for the key.
23 | ///
24 | /// true if the key is up; otherwise, false.
25 | ///
26 | bool IsKeyUp(VirtualKeyCode keyCode);
27 |
28 | ///
29 | /// Determines whether the physical key is up or down at the time the function is called regardless of whether the application thread has read the keyboard event from the message pump.
30 | ///
31 | /// The for the key.
32 | ///
33 | /// true if the key is down; otherwise, false.
34 | ///
35 | bool IsHardwareKeyDown(VirtualKeyCode keyCode);
36 |
37 | ///
38 | /// Determines whether the physical key is up or down at the time the function is called regardless of whether the application thread has read the keyboard event from the message pump.
39 | ///
40 | /// The for the key.
41 | ///
42 | /// true if the key is up; otherwise, false.
43 | ///
44 | bool IsHardwareKeyUp(VirtualKeyCode keyCode);
45 |
46 | ///
47 | /// Determines whether the toggling key is toggled on (in-effect) or not.
48 | ///
49 | /// The for the key.
50 | ///
51 | /// true if the toggling key is toggled on (in-effect); otherwise, false.
52 | ///
53 | bool IsTogglingKeyInEffect(VirtualKeyCode keyCode);
54 | }
55 | }
--------------------------------------------------------------------------------
/WindowsInput.Tests/InputSimulatorExamples.cs:
--------------------------------------------------------------------------------
1 | using NUnit.Framework;
2 | using WindowsInput.Native;
3 |
4 | namespace WindowsInput.Tests
5 | {
6 | [TestFixture]
7 | public class InputSimulatorExamples
8 | {
9 | [Test]
10 | [Explicit]
11 | public void OpenWindowsExplorer()
12 | {
13 | var sim = new InputSimulator();
14 | sim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.VK_E);
15 | }
16 |
17 | [Test]
18 | [Explicit]
19 | public void SayHello()
20 | {
21 | var sim = new InputSimulator();
22 | sim.Keyboard
23 | .ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.VK_R)
24 | .Sleep(1000)
25 | .TextEntry("notepad")
26 | .Sleep(1000)
27 | .KeyPress(VirtualKeyCode.RETURN)
28 | .Sleep(1000)
29 | .TextEntry("These are your orders if you choose to accept them...")
30 | .TextEntry("This message will self destruct in 5 seconds.")
31 | .Sleep(5000)
32 | .ModifiedKeyStroke(VirtualKeyCode.MENU, VirtualKeyCode.SPACE)
33 | .KeyPress(VirtualKeyCode.DOWN)
34 | .KeyPress(VirtualKeyCode.RETURN);
35 |
36 | var i = 10;
37 | while (i-- > 0)
38 | {
39 | sim.Keyboard.KeyPress(VirtualKeyCode.DOWN).Sleep(100);
40 | }
41 |
42 | sim.Keyboard
43 | .KeyPress(VirtualKeyCode.RETURN)
44 | .Sleep(1000)
45 | .ModifiedKeyStroke(VirtualKeyCode.MENU, VirtualKeyCode.F4)
46 | .KeyPress(VirtualKeyCode.VK_N);
47 | }
48 |
49 | [Test]
50 | [Explicit]
51 | public void AnotherTest()
52 | {
53 | var sim = new InputSimulator();
54 | sim.Keyboard.KeyPress(VirtualKeyCode.SPACE);
55 |
56 | sim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.VK_R)
57 | .Sleep(1000)
58 | .TextEntry("mspaint")
59 | .Sleep(1000)
60 | .KeyPress(VirtualKeyCode.RETURN)
61 | .Sleep(1000)
62 | .Mouse
63 | .LeftButtonDown()
64 | .MoveMouseToPositionOnVirtualDesktop(65535/2, 65535/2)
65 | .LeftButtonUp();
66 |
67 | }
68 |
69 | [Test]
70 | [Explicit]
71 | public void TestMouseMoveTo()
72 | {
73 | var sim = new InputSimulator();
74 | sim.Mouse
75 | .MoveMouseTo(0, 0)
76 | .Sleep(1000)
77 | .MoveMouseTo(65535, 65535)
78 | .Sleep(1000)
79 | .MoveMouseTo(65535/2, 65535/2);
80 | }
81 | }
82 | }
--------------------------------------------------------------------------------
/WindowsInput/Native/MouseFlag.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace WindowsInput.Native
4 | {
5 | ///
6 | /// The set of MouseFlags for use in the Flags property of the structure. (See: http://msdn.microsoft.com/en-us/library/ms646273(VS.85).aspx)
7 | ///
8 | [Flags]
9 | internal enum MouseFlag : uint // UInt32
10 | {
11 | ///
12 | /// Specifies that movement occurred.
13 | ///
14 | Move = 0x0001,
15 |
16 | ///
17 | /// Specifies that the left button was pressed.
18 | ///
19 | LeftDown = 0x0002,
20 |
21 | ///
22 | /// Specifies that the left button was released.
23 | ///
24 | LeftUp = 0x0004,
25 |
26 | ///
27 | /// Specifies that the right button was pressed.
28 | ///
29 | RightDown = 0x0008,
30 |
31 | ///
32 | /// Specifies that the right button was released.
33 | ///
34 | RightUp = 0x0010,
35 |
36 | ///
37 | /// Specifies that the middle button was pressed.
38 | ///
39 | MiddleDown = 0x0020,
40 |
41 | ///
42 | /// Specifies that the middle button was released.
43 | ///
44 | MiddleUp = 0x0040,
45 |
46 | ///
47 | /// Windows 2000/XP: Specifies that an X button was pressed.
48 | ///
49 | XDown = 0x0080,
50 |
51 | ///
52 | /// Windows 2000/XP: Specifies that an X button was released.
53 | ///
54 | XUp = 0x0100,
55 |
56 | ///
57 | /// Windows NT/2000/XP: Specifies that the wheel was moved, if the mouse has a wheel. The amount of movement is specified in mouseData.
58 | ///
59 | VerticalWheel = 0x0800,
60 |
61 | ///
62 | /// Specifies that the wheel was moved horizontally, if the mouse has a wheel. The amount of movement is specified in mouseData. Windows 2000/XP: Not supported.
63 | ///
64 | HorizontalWheel = 0x1000,
65 |
66 | ///
67 | /// Windows 2000/XP: Maps coordinates to the entire desktop. Must be used with MOUSEEVENTF_ABSOLUTE.
68 | ///
69 | VirtualDesk = 0x4000,
70 |
71 | ///
72 | /// Specifies that the dx and dy members contain normalized absolute coordinates. If the flag is not set, dxand dy contain relative data (the change in position since the last reported position). This flag can be set, or not set, regardless of what kind of mouse or other pointing device, if any, is connected to the system. For further information about relative mouse motion, see the following Remarks section.
73 | ///
74 | Absolute = 0x8000,
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/WindowsInput.SampleClient.Wpf/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30128.1
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace InputSimulator.SampleClient.Wpf.Properties
12 | {
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// Returns the cached ResourceManager instance used by this class.
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("InputSimulator.SampleClient.Wpf.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// Overrides the current thread's CurrentUICulture property for all
56 | /// resource lookups using this strongly typed resource class.
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/WindowsInput/Native/KEYBDINPUT.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace WindowsInput.Native
4 | {
5 | #pragma warning disable 649
6 | ///
7 | /// The KEYBDINPUT structure contains information about a simulated keyboard event. (see: http://msdn.microsoft.com/en-us/library/ms646271(VS.85).aspx)
8 | /// Declared in Winuser.h, include Windows.h
9 | ///
10 | ///
11 | /// Windows 2000/XP: INPUT_KEYBOARD supports nonkeyboard-input methodssuch as handwriting recognition or voice recognitionas if it were text input by using the KEYEVENTF_UNICODE flag. If KEYEVENTF_UNICODE is specified, SendInput sends a WM_KEYDOWN or WM_KEYUP message to the foreground thread's message queue with wParam equal to VK_PACKET. Once GetMessage or PeekMessage obtains this message, passing the message to TranslateMessage posts a WM_CHAR message with the Unicode character originally specified by wScan. This Unicode character will automatically be converted to the appropriate ANSI value if it is posted to an ANSI window.
12 | /// Windows 2000/XP: Set the KEYEVENTF_SCANCODE flag to define keyboard input in terms of the scan code. This is useful to simulate a physical keystroke regardless of which keyboard is currently being used. The virtual key value of a key may alter depending on the current keyboard layout or what other keys were pressed, but the scan code will always be the same.
13 | ///
14 | internal struct KEYBDINPUT
15 | {
16 | ///
17 | /// Specifies a virtual-key code. The code must be a value in the range 1 to 254. The Winuser.h header file provides macro definitions (VK_*) for each value. If the dwFlags member specifies KEYEVENTF_UNICODE, wVk must be 0.
18 | ///
19 | public UInt16 KeyCode;
20 |
21 | ///
22 | /// Specifies a hardware scan code for the key. If dwFlags specifies KEYEVENTF_UNICODE, wScan specifies a Unicode character which is to be sent to the foreground application.
23 | ///
24 | public UInt16 Scan;
25 |
26 | ///
27 | /// Specifies various aspects of a keystroke. This member can be certain combinations of the following values.
28 | /// KEYEVENTF_EXTENDEDKEY - If specified, the scan code was preceded by a prefix byte that has the value 0xE0 (224).
29 | /// KEYEVENTF_KEYUP - If specified, the key is being released. If not specified, the key is being pressed.
30 | /// KEYEVENTF_SCANCODE - If specified, wScan identifies the key and wVk is ignored.
31 | /// KEYEVENTF_UNICODE - Windows 2000/XP: If specified, the system synthesizes a VK_PACKET keystroke. The wVk parameter must be zero. This flag can only be combined with the KEYEVENTF_KEYUP flag. For more information, see the Remarks section.
32 | ///
33 | public UInt32 Flags;
34 |
35 | ///
36 | /// Time stamp for the event, in milliseconds. If this parameter is zero, the system will provide its own time stamp.
37 | ///
38 | public UInt32 Time;
39 |
40 | ///
41 | /// Specifies an additional value associated with the keystroke. Use the GetMessageExtraInfo function to obtain this information.
42 | ///
43 | public IntPtr ExtraInfo;
44 | }
45 | #pragma warning restore 649
46 | }
47 |
--------------------------------------------------------------------------------
/WindowsInput.Tests/UnicodeText/UnicodeTestForm.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace WindowsInput.Tests.UnicodeText
2 | {
3 | partial class UnicodeTestForm
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.RecievedTextBox = new System.Windows.Forms.TextBox();
32 | this.ExpectedTextBox = new System.Windows.Forms.TextBox();
33 | this.SuspendLayout();
34 | //
35 | // RecievedTextBox
36 | //
37 | this.RecievedTextBox.Dock = System.Windows.Forms.DockStyle.Top;
38 | this.RecievedTextBox.Font = new System.Drawing.Font("Segoe UI", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
39 | this.RecievedTextBox.Location = new System.Drawing.Point(0, 0);
40 | this.RecievedTextBox.Name = "RecievedTextBox";
41 | this.RecievedTextBox.Size = new System.Drawing.Size(981, 39);
42 | this.RecievedTextBox.TabIndex = 0;
43 | //
44 | // ExpectedTextBox
45 | //
46 | this.ExpectedTextBox.Dock = System.Windows.Forms.DockStyle.Bottom;
47 | this.ExpectedTextBox.Font = new System.Drawing.Font("Segoe UI", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
48 | this.ExpectedTextBox.Location = new System.Drawing.Point(0, 40);
49 | this.ExpectedTextBox.Name = "ExpectedTextBox";
50 | this.ExpectedTextBox.ReadOnly = true;
51 | this.ExpectedTextBox.Size = new System.Drawing.Size(981, 39);
52 | this.ExpectedTextBox.TabIndex = 1;
53 | //
54 | // UnicodeTestForm
55 | //
56 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
57 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
58 | this.ClientSize = new System.Drawing.Size(981, 79);
59 | this.Controls.Add(this.ExpectedTextBox);
60 | this.Controls.Add(this.RecievedTextBox);
61 | this.Name = "UnicodeTestForm";
62 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
63 | this.Text = "UnicodeTestForm";
64 | this.TopMost = true;
65 | this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
66 | this.ResumeLayout(false);
67 | this.PerformLayout();
68 |
69 | }
70 |
71 | #endregion
72 |
73 | private System.Windows.Forms.TextBox RecievedTextBox;
74 | private System.Windows.Forms.TextBox ExpectedTextBox;
75 | }
76 | }
--------------------------------------------------------------------------------
/WindowsInput/InputSimulator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace WindowsInput
4 | {
5 | ///
6 | /// Implements the interface to simulate Keyboard and Mouse input and provide the state of those input devices.
7 | ///
8 | public class InputSimulator : IInputSimulator
9 | {
10 | ///
11 | /// The instance to use for simulating keyboard input.
12 | ///
13 | private readonly IKeyboardSimulator _keyboardSimulator;
14 |
15 | ///
16 | /// The instance to use for simulating mouse input.
17 | ///
18 | private readonly IMouseSimulator _mouseSimulator;
19 |
20 | ///
21 | /// The instance to use for interpreting the state of the input devices.
22 | ///
23 | private readonly IInputDeviceStateAdaptor _inputDeviceState;
24 |
25 | ///
26 | /// Initializes a new instance of the class using the specified , and instances.
27 | ///
28 | /// The instance to use for simulating keyboard input.
29 | /// The instance to use for simulating mouse input.
30 | /// The instance to use for interpreting the state of input devices.
31 | public InputSimulator(IKeyboardSimulator keyboardSimulator, IMouseSimulator mouseSimulator, IInputDeviceStateAdaptor inputDeviceStateAdaptor)
32 | {
33 | _keyboardSimulator = keyboardSimulator;
34 | _mouseSimulator = mouseSimulator;
35 | _inputDeviceState = inputDeviceStateAdaptor;
36 | }
37 |
38 | ///
39 | /// Initializes a new instance of the class using the default , and instances.
40 | ///
41 | public InputSimulator()
42 | {
43 | _keyboardSimulator = new KeyboardSimulator(this);
44 | _mouseSimulator = new MouseSimulator(this);
45 | _inputDeviceState = new WindowsInputDeviceStateAdaptor();
46 | }
47 |
48 | ///
49 | /// Gets the instance for simulating Keyboard input.
50 | ///
51 | /// The instance.
52 | public IKeyboardSimulator Keyboard
53 | {
54 | get { return _keyboardSimulator; }
55 | }
56 |
57 | ///
58 | /// Gets the instance for simulating Mouse input.
59 | ///
60 | /// The instance.
61 | public IMouseSimulator Mouse
62 | {
63 | get { return _mouseSimulator; }
64 | }
65 |
66 | ///
67 | /// Gets the instance for determining the state of the various input devices.
68 | ///
69 | /// The instance.
70 | public IInputDeviceStateAdaptor InputDeviceState
71 | {
72 | get { return _inputDeviceState; }
73 | }
74 | }
75 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Windows Input Simulator (C# SendInput Wrapper - Simulate Keyboard and Mouse)
2 | ============================================================================
3 | The Windows Input Simulator provides a simple .NET (C#) interface to simulate Keyboard or Mouse input using the Win32 SendInput method. All of the Interop is done for you and there's a simple programming model for sending multiple keystrokes.
4 |
5 | Windows Forms provides the SendKeys method which can simulate text entry, but not actual key strokes. Windows Input Simulator can be used in WPF, Windows Forms and Console Applications to synthesize or simulate any Keyboard input including Control, Alt, Shift, Tab, Enter, Space, Backspace, the Windows Key, Caps Lock, Num Lock, Scroll Lock, Volume Up/Down and Mute, Web, Mail, Search, Favorites, Function Keys, Back and Forward navigation keys, Programmable keys and any other key defined in the Virtual Key table. It provides a simple API to simulate text entry, key down, key up, key press and complex modified key strokes and chords.
6 |
7 | NuGet
8 | ------
9 | Install-Package InputSimulator
10 |
11 | Examples
12 | ==========
13 |
14 | Example: Single key press
15 | -------------
16 | ```csharp
17 | public void PressTheSpacebar()
18 | {
19 | InputSimulator.SimulateKeyPress(VirtualKeyCode.SPACE);
20 | }
21 | ```
22 |
23 | Example: Key-down and Key-up
24 | ------------
25 | ```csharp
26 | public void ShoutHello()
27 | {
28 | // Simulate each key stroke
29 | InputSimulator.SimulateKeyDown(VirtualKeyCode.SHIFT);
30 | InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_H);
31 | InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_E);
32 | InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_L);
33 | InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_L);
34 | InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_O);
35 | InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_1);
36 | InputSimulator.SimulateKeyUp(VirtualKeyCode.SHIFT);
37 |
38 | // Alternatively you can simulate text entry to acheive the same end result
39 | InputSimulator.SimulateTextEntry("HELLO!");
40 | }
41 | ```
42 |
43 | Example: Modified keystrokes such as CTRL-C
44 | --------------
45 | ```csharp
46 | public void SimulateSomeModifiedKeystrokes()
47 | {
48 | // CTRL-C (effectively a copy command in many situations)
49 | InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_C);
50 |
51 | // You can simulate chords with multiple modifiers
52 | // For example CTRL-K-C whic is simulated as
53 | // CTRL-down, K, C, CTRL-up
54 | InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, new [] {VirtualKeyCode.VK_K, VirtualKeyCode.VK_C});
55 |
56 | // You can simulate complex chords with multiple modifiers and key presses
57 | // For example CTRL-ALT-SHIFT-ESC-K which is simulated as
58 | // CTRL-down, ALT-down, SHIFT-down, press ESC, press K, SHIFT-up, ALT-up, CTRL-up
59 | InputSimulator.SimulateModifiedKeyStroke(
60 | new[] { VirtualKeyCode.CONTROL, VirtualKeyCode.MENU, VirtualKeyCode.SHIFT },
61 | new[] { VirtualKeyCode.ESCAPE, VirtualKeyCode.VK_K });
62 | }
63 | ```
64 |
65 | Example: Simulate text entry
66 | --------
67 | ```csharp
68 | public void SayHello()
69 | {
70 | InputSimulator.SimulateTextEntry("Say hello!");
71 | }
72 | ```
73 |
74 | Example: Determine the state of different types of keys
75 | ------------
76 | ```csharp
77 | public void GetKeyStatus()
78 | {
79 | // Determines if the shift key is currently down
80 | var isShiftKeyDown = InputSimulator.IsKeyDown(VirtualKeyCode.SHIFT);
81 |
82 | // Determines if the caps lock key is currently in effect (toggled on)
83 | var isCapsLockOn = InputSimulator.IsTogglingKeyInEffect(VirtualKeyCode.CAPITAL);
84 | }
85 | ```
86 |
87 | History
88 | ============
89 | It was originally written for use in the WpfKB (WPF Touch Screen Keyboard) project to simulate real keyboard entry to the active window. After looking for a comprehensive wrapper for the Win32 and User32 input simulation methods and coming up dry I decided to write and open-source this project. I hope it helps someone out there!
90 |
--------------------------------------------------------------------------------
/WindowsInput/WindowsInput.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.30729
7 | 2.0
8 | {3549CD6F-80F8-450F-B99E-CF0A736B1F2A}
9 | Library
10 | Properties
11 | WindowsInput
12 | WindowsInput
13 | v2.0
14 | 512
15 |
16 |
17 |
18 |
19 | 3.5
20 |
21 |
22 |
23 |
24 | true
25 | full
26 | false
27 | bin\Debug\
28 | DEBUG;TRACE
29 | prompt
30 | 4
31 | bin\Debug\WindowsInput.xml
32 | true
33 | AllRules.ruleset
34 |
35 |
36 | pdbonly
37 | true
38 | bin\Release\
39 | TRACE
40 | prompt
41 | 4
42 | bin\Release\WindowsInput.xml
43 | AllRules.ruleset
44 |
45 |
46 | true
47 |
48 |
49 | WindowsInput.snk
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
92 |
--------------------------------------------------------------------------------
/WindowsInput.Tests/WindowsInput.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.30703
7 | 2.0
8 | {93982D2F-BEAD-49F7-86A9-C68159410F28}
9 | Library
10 | Properties
11 | WindowsInput.Tests
12 | WindowsInput.Tests
13 | v4.5
14 | 512
15 |
16 | ..\
17 | true
18 |
19 |
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | DEBUG;TRACE
25 | prompt
26 | 4
27 | false
28 |
29 |
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 | false
37 |
38 |
39 | true
40 |
41 |
42 | WindowsInput.Tests.snk
43 |
44 |
45 |
46 | ..\packages\HtmlAgilityPack.1.4.6\lib\Net45\HtmlAgilityPack.dll
47 |
48 |
49 | ..\packages\NUnit.2.6.2\lib\nunit.framework.dll
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 | Form
67 |
68 |
69 | UnicodeTestForm.cs
70 |
71 |
72 |
73 |
74 |
75 | {3549CD6F-80F8-450F-B99E-CF0A736B1F2A}
76 | WindowsInput
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 | UnicodeTestForm.cs
86 |
87 |
88 |
89 |
90 |
97 |
--------------------------------------------------------------------------------
/WindowsInput.SampleClient.Wpf/WindowsInput.SampleClient.Wpf.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | x86
6 | 8.0.30703
7 | 2.0
8 | {DE70B414-25CB-4C64-82EE-3955FECDF762}
9 | WinExe
10 | Properties
11 | InputSimulator.SampleClient.Wpf
12 | InputSimulator.SampleClient.Wpf
13 | v4.0
14 | Client
15 | 512
16 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
17 | 4
18 |
19 |
20 | x86
21 | true
22 | full
23 | false
24 | bin\Debug\
25 | DEBUG;TRACE
26 | prompt
27 | 4
28 |
29 |
30 | x86
31 | pdbonly
32 | true
33 | bin\Release\
34 | TRACE
35 | prompt
36 | 4
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | 4.0
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | MSBuild:Compile
56 | Designer
57 |
58 |
59 | MSBuild:Compile
60 | Designer
61 |
62 |
63 | App.xaml
64 | Code
65 |
66 |
67 | MainWindow.xaml
68 | Code
69 |
70 |
71 |
72 |
73 | Code
74 |
75 |
76 | True
77 | True
78 | Resources.resx
79 |
80 |
81 | True
82 | Settings.settings
83 | True
84 |
85 |
86 | ResXFileCodeGenerator
87 | Resources.Designer.cs
88 |
89 |
90 | SettingsSingleFileGenerator
91 | Settings.Designer.cs
92 |
93 |
94 |
95 |
96 |
97 | {3549CD6F-80F8-450F-B99E-CF0A736B1F2A}
98 | InputSimulator
99 |
100 |
101 |
102 |
109 |
--------------------------------------------------------------------------------
/WindowsInput/IKeyboardSimulator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using WindowsInput.Native;
4 |
5 | namespace WindowsInput
6 | {
7 | ///
8 | /// The service contract for a keyboard simulator for the Windows platform.
9 | ///
10 | public interface IKeyboardSimulator
11 | {
12 | ///
13 | /// Gets the instance for simulating Mouse input.
14 | ///
15 | /// The instance.
16 | IMouseSimulator Mouse { get; }
17 |
18 | ///
19 | /// Simulates the key down gesture for the specified key.
20 | ///
21 | /// The for the key.
22 | IKeyboardSimulator KeyDown(VirtualKeyCode keyCode);
23 |
24 | ///
25 | /// Simulates the key press gesture for the specified key.
26 | ///
27 | /// The for the key.
28 | IKeyboardSimulator KeyPress(VirtualKeyCode keyCode);
29 |
30 | ///
31 | /// Simulates a key press for each of the specified key codes in the order they are specified.
32 | ///
33 | ///
34 | IKeyboardSimulator KeyPress(params VirtualKeyCode[] keyCodes);
35 |
36 | ///
37 | /// Simulates the key up gesture for the specified key.
38 | ///
39 | /// The for the key.
40 | IKeyboardSimulator KeyUp(VirtualKeyCode keyCode);
41 |
42 | ///
43 | /// Simulates a modified keystroke where there are multiple modifiers and multiple keys like CTRL-ALT-K-C where CTRL and ALT are the modifierKeys and K and C are the keys.
44 | /// The flow is Modifiers KeyDown in order, Keys Press in order, Modifiers KeyUp in reverse order.
45 | ///
46 | /// The list of s for the modifier keys.
47 | /// The list of s for the keys to simulate.
48 | IKeyboardSimulator ModifiedKeyStroke(IEnumerable modifierKeyCodes, IEnumerable keyCodes);
49 |
50 | ///
51 | /// Simulates a modified keystroke where there are multiple modifiers and one key like CTRL-ALT-C where CTRL and ALT are the modifierKeys and C is the key.
52 | /// The flow is Modifiers KeyDown in order, Key Press, Modifiers KeyUp in reverse order.
53 | ///
54 | /// The list of s for the modifier keys.
55 | /// The for the key.
56 | IKeyboardSimulator ModifiedKeyStroke(IEnumerable modifierKeyCodes, VirtualKeyCode keyCode);
57 |
58 | ///
59 | /// Simulates a modified keystroke where there is one modifier and multiple keys like CTRL-K-C where CTRL is the modifierKey and K and C are the keys.
60 | /// The flow is Modifier KeyDown, Keys Press in order, Modifier KeyUp.
61 | ///
62 | /// The for the modifier key.
63 | /// The list of s for the keys to simulate.
64 | IKeyboardSimulator ModifiedKeyStroke(VirtualKeyCode modifierKey, IEnumerable keyCodes);
65 |
66 | ///
67 | /// Simulates a simple modified keystroke like CTRL-C where CTRL is the modifierKey and C is the key.
68 | /// The flow is Modifier KeyDown, Key Press, Modifier KeyUp.
69 | ///
70 | /// The for the modifier key.
71 | /// The for the key.
72 | IKeyboardSimulator ModifiedKeyStroke(VirtualKeyCode modifierKeyCode, VirtualKeyCode keyCode);
73 |
74 | ///
75 | /// Simulates uninterrupted text entry via the keyboard.
76 | ///
77 | /// The text to be simulated.
78 | IKeyboardSimulator TextEntry(string text);
79 |
80 | ///
81 | /// Simulates a single character text entry via the keyboard.
82 | ///
83 | /// The unicode character to be simulated.
84 | IKeyboardSimulator TextEntry(char character);
85 |
86 | ///
87 | /// Sleeps the executing thread to create a pause between simulated inputs.
88 | ///
89 | /// The number of milliseconds to wait.
90 | IKeyboardSimulator Sleep(int millsecondsTimeout);
91 |
92 | ///
93 | /// Sleeps the executing thread to create a pause between simulated inputs.
94 | ///
95 | /// The time to wait.
96 | IKeyboardSimulator Sleep(TimeSpan timeout);
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/WindowsInput/Native/MOUSEINPUT.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace WindowsInput.Native
4 | {
5 | #pragma warning disable 649
6 | ///
7 | /// The MOUSEINPUT structure contains information about a simulated mouse event. (see: http://msdn.microsoft.com/en-us/library/ms646273(VS.85).aspx)
8 | /// Declared in Winuser.h, include Windows.h
9 | ///
10 | ///
11 | /// If the mouse has moved, indicated by MOUSEEVENTF_MOVE, dx and dy specify information about that movement. The information is specified as absolute or relative integer values.
12 | /// If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535. The event procedure maps these coordinates onto the display surface. Coordinate (0,0) maps onto the upper-left corner of the display surface; coordinate (65535,65535) maps onto the lower-right corner. In a multimonitor system, the coordinates map to the primary monitor.
13 | /// Windows 2000/XP: If MOUSEEVENTF_VIRTUALDESK is specified, the coordinates map to the entire virtual desktop.
14 | /// If the MOUSEEVENTF_ABSOLUTE value is not specified, dx and dy specify movement relative to the previous mouse event (the last reported position). Positive values mean the mouse moved right (or down); negative values mean the mouse moved left (or up).
15 | /// Relative mouse motion is subject to the effects of the mouse speed and the two-mouse threshold values. A user sets these three values with the Pointer Speed slider of the Control Panel's Mouse Properties sheet. You can obtain and set these values using the SystemParametersInfo function.
16 | /// The system applies two tests to the specified relative mouse movement. If the specified distance along either the x or y axis is greater than the first mouse threshold value, and the mouse speed is not zero, the system doubles the distance. If the specified distance along either the x or y axis is greater than the second mouse threshold value, and the mouse speed is equal to two, the system doubles the distance that resulted from applying the first threshold test. It is thus possible for the system to multiply specified relative mouse movement along the x or y axis by up to four times.
17 | ///
18 | internal struct MOUSEINPUT
19 | {
20 | ///
21 | /// Specifies the absolute position of the mouse, or the amount of motion since the last mouse event was generated, depending on the value of the dwFlags member. Absolute data is specified as the x coordinate of the mouse; relative data is specified as the number of pixels moved.
22 | ///
23 | public Int32 X;
24 |
25 | ///
26 | /// Specifies the absolute position of the mouse, or the amount of motion since the last mouse event was generated, depending on the value of the dwFlags member. Absolute data is specified as the y coordinate of the mouse; relative data is specified as the number of pixels moved.
27 | ///
28 | public Int32 Y;
29 |
30 | ///
31 | /// If dwFlags contains MOUSEEVENTF_WHEEL, then mouseData specifies the amount of wheel movement. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user. One wheel click is defined as WHEEL_DELTA, which is 120.
32 | /// Windows Vista: If dwFlags contains MOUSEEVENTF_HWHEEL, then dwData specifies the amount of wheel movement. A positive value indicates that the wheel was rotated to the right; a negative value indicates that the wheel was rotated to the left. One wheel click is defined as WHEEL_DELTA, which is 120.
33 | /// Windows 2000/XP: IfdwFlags does not contain MOUSEEVENTF_WHEEL, MOUSEEVENTF_XDOWN, or MOUSEEVENTF_XUP, then mouseData should be zero.
34 | /// If dwFlags contains MOUSEEVENTF_XDOWN or MOUSEEVENTF_XUP, then mouseData specifies which X buttons were pressed or released. This value may be any combination of the following flags.
35 | ///
36 | public UInt32 MouseData;
37 |
38 | ///
39 | /// A set of bit flags that specify various aspects of mouse motion and button clicks. The bits in this member can be any reasonable combination of the following values.
40 | /// The bit flags that specify mouse button status are set to indicate changes in status, not ongoing conditions. For example, if the left mouse button is pressed and held down, MOUSEEVENTF_LEFTDOWN is set when the left button is first pressed, but not for subsequent motions. Similarly, MOUSEEVENTF_LEFTUP is set only when the button is first released.
41 | /// You cannot specify both the MOUSEEVENTF_WHEEL flag and either MOUSEEVENTF_XDOWN or MOUSEEVENTF_XUP flags simultaneously in the dwFlags parameter, because they both require use of the mouseData field.
42 | ///
43 | public UInt32 Flags;
44 |
45 | ///
46 | /// Time stamp for the event, in milliseconds. If this parameter is 0, the system will provide its own time stamp.
47 | ///
48 | public UInt32 Time;
49 |
50 | ///
51 | /// Specifies an additional value associated with the mouse event. An application calls GetMessageExtraInfo to obtain this extra information.
52 | ///
53 | public IntPtr ExtraInfo;
54 | }
55 | #pragma warning restore 649
56 | }
--------------------------------------------------------------------------------
/WindowsInput.SampleClient.Wpf/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/WindowsInput/IMouseSimulator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace WindowsInput
4 | {
5 | ///
6 | /// The service contract for a mouse simulator for the Windows platform.
7 | ///
8 | public interface IMouseSimulator
9 | {
10 | ///
11 | /// Gets the instance for simulating Keyboard input.
12 | ///
13 | /// The instance.
14 | IKeyboardSimulator Keyboard { get; }
15 |
16 | ///
17 | /// Simulates mouse movement by the specified distance measured as a delta from the current mouse location in pixels.
18 | ///
19 | /// The distance in pixels to move the mouse horizontally.
20 | /// The distance in pixels to move the mouse vertically.
21 | IMouseSimulator MoveMouseBy(int pixelDeltaX, int pixelDeltaY);
22 |
23 | ///
24 | /// Simulates mouse movement to the specified location on the primary display device.
25 | ///
26 | /// The destination's absolute X-coordinate on the primary display device where 0 is the extreme left hand side of the display device and 65535 is the extreme right hand side of the display device.
27 | /// The destination's absolute Y-coordinate on the primary display device where 0 is the top of the display device and 65535 is the bottom of the display device.
28 | IMouseSimulator MoveMouseTo(double absoluteX, double absoluteY);
29 |
30 | ///
31 | /// Simulates mouse movement to the specified location on the Virtual Desktop which includes all active displays.
32 | ///
33 | /// The destination's absolute X-coordinate on the virtual desktop where 0 is the left hand side of the virtual desktop and 65535 is the extreme right hand side of the virtual desktop.
34 | /// The destination's absolute Y-coordinate on the virtual desktop where 0 is the top of the virtual desktop and 65535 is the bottom of the virtual desktop.
35 | IMouseSimulator MoveMouseToPositionOnVirtualDesktop(double absoluteX, double absoluteY);
36 |
37 | ///
38 | /// Simulates a mouse left button down gesture.
39 | ///
40 | IMouseSimulator LeftButtonDown();
41 |
42 | ///
43 | /// Simulates a mouse left button up gesture.
44 | ///
45 | IMouseSimulator LeftButtonUp();
46 |
47 | ///
48 | /// Simulates a mouse left button click gesture.
49 | ///
50 | IMouseSimulator LeftButtonClick();
51 |
52 | ///
53 | /// Simulates a mouse left button double-click gesture.
54 | ///
55 | IMouseSimulator LeftButtonDoubleClick();
56 |
57 | ///
58 | /// Simulates a mouse right button down gesture.
59 | ///
60 | IMouseSimulator RightButtonDown();
61 |
62 | ///
63 | /// Simulates a mouse right button up gesture.
64 | ///
65 | IMouseSimulator RightButtonUp();
66 |
67 | ///
68 | /// Simulates a mouse right button click gesture.
69 | ///
70 | IMouseSimulator RightButtonClick();
71 |
72 | ///
73 | /// Simulates a mouse right button double-click gesture.
74 | ///
75 | IMouseSimulator RightButtonDoubleClick();
76 |
77 | ///
78 | /// Simulates a mouse X button down gesture.
79 | ///
80 | /// The button id.
81 | IMouseSimulator XButtonDown(int buttonId);
82 |
83 | ///
84 | /// Simulates a mouse X button up gesture.
85 | ///
86 | /// The button id.
87 | IMouseSimulator XButtonUp(int buttonId);
88 |
89 | ///
90 | /// Simulates a mouse X button click gesture.
91 | ///
92 | /// The button id.
93 | IMouseSimulator XButtonClick(int buttonId);
94 |
95 | ///
96 | /// Simulates a mouse X button double-click gesture.
97 | ///
98 | /// The button id.
99 | IMouseSimulator XButtonDoubleClick(int buttonId);
100 |
101 | ///
102 | /// Simulates mouse vertical wheel scroll gesture.
103 | ///
104 | /// The amount to scroll in clicks. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user.
105 | IMouseSimulator VerticalScroll(int scrollAmountInClicks);
106 |
107 | ///
108 | /// Simulates a mouse horizontal wheel scroll gesture. Supported by Windows Vista and later.
109 | ///
110 | /// The amount to scroll in clicks. A positive value indicates that the wheel was rotated to the right; a negative value indicates that the wheel was rotated to the left.
111 | IMouseSimulator HorizontalScroll(int scrollAmountInClicks);
112 |
113 | ///
114 | /// Sleeps the executing thread to create a pause between simulated inputs.
115 | ///
116 | /// The number of milliseconds to wait.
117 | IMouseSimulator Sleep(int millsecondsTimeout);
118 |
119 | ///
120 | /// Sleeps the executing thread to create a pause between simulated inputs.
121 | ///
122 | /// The time to wait.
123 | IMouseSimulator Sleep(TimeSpan timeout);
124 | }
125 | }
--------------------------------------------------------------------------------
/WindowsInput.Tests/UnicodeText/UnicodeTestForm.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
--------------------------------------------------------------------------------
/BuildProcessTemplates/UpgradeTemplate.xaml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | [New Microsoft.TeamFoundation.Build.Workflow.Activities.AgentSettings() With {.MaxWaitTime = New System.TimeSpan(4, 0, 0), .MaxExecutionTime = New System.TimeSpan(0, 0, 0), .TagComparison = Microsoft.TeamFoundation.Build.Workflow.Activities.TagComparison.MatchExactly }]
21 |
22 |
23 |
24 | [Microsoft.TeamFoundation.Build.Workflow.Activities.ToolPlatform.Auto]
25 | [False]
26 | [False]
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | [Microsoft.TeamFoundation.VersionControl.Client.RecursionType.OneLevel]
37 | [Microsoft.TeamFoundation.Build.Workflow.BuildVerbosity.Normal]
38 |
39 |
40 |
41 | All
42 | Assembly references and imported namespaces serialized as XML namespaces
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/.nuget/NuGet.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildProjectDirectory)\..\
5 |
6 |
7 | false
8 |
9 |
10 | false
11 |
12 |
13 | true
14 |
15 |
16 | false
17 |
18 |
19 |
20 |
21 |
22 |
26 |
27 |
28 |
29 |
30 | $([System.IO.Path]::Combine($(SolutionDir), ".nuget"))
31 | $([System.IO.Path]::Combine($(ProjectDir), "packages.config"))
32 | $([System.IO.Path]::Combine($(SolutionDir), "packages"))
33 |
34 |
35 |
36 |
37 | $(SolutionDir).nuget
38 | packages.config
39 | $(SolutionDir)packages
40 |
41 |
42 |
43 |
44 | $(NuGetToolsPath)\nuget.exe
45 | @(PackageSource)
46 |
47 | "$(NuGetExePath)"
48 | mono --runtime=v4.0.30319 $(NuGetExePath)
49 |
50 | $(TargetDir.Trim('\\'))
51 |
52 | -RequireConsent
53 |
54 | $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(RequireConsentSwitch) -o "$(PackagesDir)"
55 | $(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols
56 |
57 |
58 |
59 | RestorePackages;
60 | $(BuildDependsOn);
61 |
62 |
63 |
64 |
65 | $(BuildDependsOn);
66 | BuildPackage;
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
89 |
90 |
93 |
94 |
95 |
96 |
98 |
99 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
150 |
151 |
152 |
153 |
--------------------------------------------------------------------------------
/WindowsInput/Native/NativeMethods.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace WindowsInput.Native
5 | {
6 | ///
7 | /// References all of the Native Windows API methods for the WindowsInput functionality.
8 | ///
9 | internal static class NativeMethods
10 | {
11 | ///
12 | /// The GetAsyncKeyState function determines whether a key is up or down at the time the function is called, and whether the key was pressed after a previous call to GetAsyncKeyState. (See: http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx)
13 | ///
14 | /// Specifies one of 256 possible virtual-key codes. For more information, see Virtual Key Codes. Windows NT/2000/XP: You can use left- and right-distinguishing constants to specify certain keys. See the Remarks section for further information.
15 | ///
16 | /// If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState. However, you should not rely on this last behavior; for more information, see the Remarks.
17 | ///
18 | /// Windows NT/2000/XP: The return value is zero for the following cases:
19 | /// - The current desktop is not the active desktop
20 | /// - The foreground thread belongs to another process and the desktop does not allow the hook or the journal record.
21 | ///
22 | /// Windows 95/98/Me: The return value is the global asynchronous key state for each virtual key. The system does not check which thread has the keyboard focus.
23 | ///
24 | /// Windows 95/98/Me: Windows 95 does not support the left- and right-distinguishing constants. If you call GetAsyncKeyState with these constants, the return value is zero.
25 | ///
26 | ///
27 | /// The GetAsyncKeyState function works with mouse buttons. However, it checks on the state of the physical mouse buttons, not on the logical mouse buttons that the physical buttons are mapped to. For example, the call GetAsyncKeyState(VK_LBUTTON) always returns the state of the left physical mouse button, regardless of whether it is mapped to the left or right logical mouse button. You can determine the system's current mapping of physical mouse buttons to logical mouse buttons by calling
28 | /// Copy CodeGetSystemMetrics(SM_SWAPBUTTON) which returns TRUE if the mouse buttons have been swapped.
29 | ///
30 | /// Although the least significant bit of the return value indicates whether the key has been pressed since the last query, due to the pre-emptive multitasking nature of Windows, another application can call GetAsyncKeyState and receive the "recently pressed" bit instead of your application. The behavior of the least significant bit of the return value is retained strictly for compatibility with 16-bit Windows applications (which are non-preemptive) and should not be relied upon.
31 | ///
32 | /// You can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the vKey parameter. This gives the state of the SHIFT, CTRL, or ALT keys without distinguishing between left and right.
33 | ///
34 | /// Windows NT/2000/XP: You can use the following virtual-key code constants as values for vKey to distinguish between the left and right instances of those keys.
35 | ///
36 | /// Code Meaning
37 | /// VK_LSHIFT Left-shift key.
38 | /// VK_RSHIFT Right-shift key.
39 | /// VK_LCONTROL Left-control key.
40 | /// VK_RCONTROL Right-control key.
41 | /// VK_LMENU Left-menu key.
42 | /// VK_RMENU Right-menu key.
43 | ///
44 | /// These left- and right-distinguishing constants are only available when you call the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.
45 | ///
46 | [DllImport("user32.dll", SetLastError = true)]
47 | public static extern Int16 GetAsyncKeyState(UInt16 virtualKeyCode);
48 |
49 | ///
50 | /// The GetKeyState function retrieves the status of the specified virtual key. The status specifies whether the key is up, down, or toggled (on, off alternating each time the key is pressed). (See: http://msdn.microsoft.com/en-us/library/ms646301(VS.85).aspx)
51 | ///
52 | ///
53 | /// Specifies a virtual key. If the desired virtual key is a letter or digit (A through Z, a through z, or 0 through 9), nVirtKey must be set to the ASCII value of that character. For other keys, it must be a virtual-key code.
54 | /// If a non-English keyboard layout is used, virtual keys with values in the range ASCII A through Z and 0 through 9 are used to specify most of the character keys. For example, for the German keyboard layout, the virtual key of value ASCII O (0x4F) refers to the "o" key, whereas VK_OEM_1 refers to the "o with umlaut" key.
55 | ///
56 | ///
57 | /// The return value specifies the status of the specified virtual key, as follows:
58 | /// If the high-order bit is 1, the key is down; otherwise, it is up.
59 | /// If the low-order bit is 1, the key is toggled. A key, such as the CAPS LOCK key, is toggled if it is turned on. The key is off and untoggled if the low-order bit is 0. A toggle key's indicator light (if any) on the keyboard will be on when the key is toggled, and off when the key is untoggled.
60 | ///
61 | ///
62 | /// The key status returned from this function changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information.
63 | /// An application calls GetKeyState in response to a keyboard-input message. This function retrieves the state of the key when the input message was generated.
64 | /// To retrieve state information for all the virtual keys, use the GetKeyboardState function.
65 | /// An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the nVirtKey parameter. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as values for nVirtKey to distinguish between the left and right instances of those keys.
66 | /// VK_LSHIFT
67 | /// VK_RSHIFT
68 | /// VK_LCONTROL
69 | /// VK_RCONTROL
70 | /// VK_LMENU
71 | /// VK_RMENU
72 | ///
73 | /// These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.
74 | ///
75 | [DllImport("user32.dll", SetLastError = true)]
76 | public static extern Int16 GetKeyState(UInt16 virtualKeyCode);
77 |
78 | ///
79 | /// The SendInput function synthesizes keystrokes, mouse motions, and button clicks.
80 | ///
81 | /// Number of structures in the Inputs array.
82 | /// Pointer to an array of INPUT structures. Each structure represents an event to be inserted into the keyboard or mouse input stream.
83 | /// Specifies the size, in bytes, of an INPUT structure. If cbSize is not the size of an INPUT structure, the function fails.
84 | /// The function returns the number of events that it successfully inserted into the keyboard or mouse input stream. If the function returns zero, the input was already blocked by another thread. To get extended error information, call GetLastError.Microsoft Windows Vista. This function fails when it is blocked by User Interface Privilege Isolation (UIPI). Note that neither GetLastError nor the return value will indicate the failure was caused by UIPI blocking.
85 | ///
86 | /// Microsoft Windows Vista. This function is subject to UIPI. Applications are permitted to inject input only into applications that are at an equal or lesser integrity level.
87 | /// The SendInput function inserts the events in the INPUT structures serially into the keyboard or mouse input stream. These events are not interspersed with other keyboard or mouse input events inserted either by the user (with the keyboard or mouse) or by calls to keybd_event, mouse_event, or other calls to SendInput.
88 | /// This function does not reset the keyboard's current state. Any keys that are already pressed when the function is called might interfere with the events that this function generates. To avoid this problem, check the keyboard's state with the GetAsyncKeyState function and correct as necessary.
89 | ///
90 | [DllImport("user32.dll", SetLastError = true)]
91 | public static extern UInt32 SendInput(UInt32 numberOfInputs, INPUT[] inputs, Int32 sizeOfInputStructure);
92 |
93 | ///
94 | /// The GetMessageExtraInfo function retrieves the extra message information for the current thread. Extra message information is an application- or driver-defined value associated with the current thread's message queue.
95 | ///
96 | ///
97 | /// To set a thread's extra message information, use the SetMessageExtraInfo function.
98 | [DllImport("user32.dll")]
99 | public static extern IntPtr GetMessageExtraInfo();
100 |
101 | ///
102 | /// Used to find the keyboard input scan code for single key input. Some applications do not receive the input when scan is not set.
103 | ///
104 | ///
105 | ///
106 | ///
107 | [DllImport("user32.dll")]
108 | public static extern UInt32 MapVirtualKey(UInt32 uCode, UInt32 uMapType);
109 | }
110 | }
--------------------------------------------------------------------------------
/WindowsInput/KeyboardSimulator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Threading;
4 | using WindowsInput.Native;
5 |
6 | namespace WindowsInput
7 | {
8 | ///
9 | /// Implements the interface by calling the an to simulate Keyboard gestures.
10 | ///
11 | public class KeyboardSimulator : IKeyboardSimulator
12 | {
13 | private readonly IInputSimulator _inputSimulator;
14 |
15 | ///
16 | /// The instance of the to use for dispatching messages.
17 | ///
18 | private readonly IInputMessageDispatcher _messageDispatcher;
19 |
20 | ///
21 | /// Initializes a new instance of the class using an instance of a for dispatching messages.
22 | ///
23 | /// The that owns this instance.
24 | public KeyboardSimulator(IInputSimulator inputSimulator)
25 | {
26 | if (inputSimulator == null) throw new ArgumentNullException("inputSimulator");
27 |
28 | _inputSimulator = inputSimulator;
29 | _messageDispatcher = new WindowsInputMessageDispatcher();
30 | }
31 |
32 | ///
33 | /// Initializes a new instance of the class using the specified for dispatching messages.
34 | ///
35 | /// The that owns this instance.
36 | /// The to use for dispatching messages.
37 | /// If null is passed as the .
38 | internal KeyboardSimulator(IInputSimulator inputSimulator, IInputMessageDispatcher messageDispatcher)
39 | {
40 | if (inputSimulator == null) throw new ArgumentNullException("inputSimulator");
41 |
42 | if (messageDispatcher == null)
43 | throw new InvalidOperationException(
44 | string.Format("The {0} cannot operate with a null {1}. Please provide a valid {1} instance to use for dispatching {2} messages.",
45 | typeof(KeyboardSimulator).Name, typeof(IInputMessageDispatcher).Name, typeof(INPUT).Name));
46 |
47 | _inputSimulator = inputSimulator;
48 | _messageDispatcher = messageDispatcher;
49 | }
50 |
51 | ///
52 | /// Gets the instance for simulating Mouse input.
53 | ///
54 | /// The instance.
55 | public IMouseSimulator Mouse { get { return _inputSimulator.Mouse; } }
56 |
57 | private void ModifiersDown(InputBuilder builder, IEnumerable modifierKeyCodes)
58 | {
59 | if (modifierKeyCodes == null) return;
60 | foreach (var key in modifierKeyCodes) builder.AddKeyDown(key);
61 | }
62 |
63 | private void ModifiersUp(InputBuilder builder, IEnumerable modifierKeyCodes)
64 | {
65 | if (modifierKeyCodes == null) return;
66 |
67 | // Key up in reverse (I miss LINQ)
68 | var stack = new Stack(modifierKeyCodes);
69 | while (stack.Count > 0) builder.AddKeyUp(stack.Pop());
70 | }
71 |
72 | private void KeysPress(InputBuilder builder, IEnumerable keyCodes)
73 | {
74 | if (keyCodes == null) return;
75 | foreach (var key in keyCodes) builder.AddKeyPress(key);
76 | }
77 |
78 | ///
79 | /// Sends the list of messages using the instance.
80 | ///
81 | /// The of messages to send.
82 | private void SendSimulatedInput(INPUT[] inputList)
83 | {
84 | _messageDispatcher.DispatchInput(inputList);
85 | }
86 |
87 | ///
88 | /// Calls the Win32 SendInput method to simulate a KeyDown.
89 | ///
90 | /// The to press
91 | public IKeyboardSimulator KeyDown(VirtualKeyCode keyCode)
92 | {
93 | var inputList = new InputBuilder().AddKeyDown(keyCode).ToArray();
94 | SendSimulatedInput(inputList);
95 | return this;
96 | }
97 |
98 | ///
99 | /// Calls the Win32 SendInput method to simulate a KeyUp.
100 | ///
101 | /// The to lift up
102 | public IKeyboardSimulator KeyUp(VirtualKeyCode keyCode)
103 | {
104 | var inputList = new InputBuilder().AddKeyUp(keyCode).ToArray();
105 | SendSimulatedInput(inputList);
106 | return this;
107 | }
108 |
109 | ///
110 | /// Calls the Win32 SendInput method with a KeyDown and KeyUp message in the same input sequence in order to simulate a Key PRESS.
111 | ///
112 | /// The to press
113 | public IKeyboardSimulator KeyPress(VirtualKeyCode keyCode)
114 | {
115 | var inputList = new InputBuilder().AddKeyPress(keyCode).ToArray();
116 | SendSimulatedInput(inputList);
117 | return this;
118 | }
119 |
120 | ///
121 | /// Simulates a key press for each of the specified key codes in the order they are specified.
122 | ///
123 | ///
124 | public IKeyboardSimulator KeyPress(params VirtualKeyCode[] keyCodes)
125 | {
126 | var builder = new InputBuilder();
127 | KeysPress(builder, keyCodes);
128 | SendSimulatedInput(builder.ToArray());
129 | return this;
130 | }
131 |
132 | ///
133 | /// Simulates a simple modified keystroke like CTRL-C where CTRL is the modifierKey and C is the key.
134 | /// The flow is Modifier KeyDown, Key Press, Modifier KeyUp.
135 | ///
136 | /// The modifier key
137 | /// The key to simulate
138 | public IKeyboardSimulator ModifiedKeyStroke(VirtualKeyCode modifierKeyCode, VirtualKeyCode keyCode)
139 | {
140 | ModifiedKeyStroke(new[] { modifierKeyCode }, new[] { keyCode });
141 | return this;
142 | }
143 |
144 | ///
145 | /// Simulates a modified keystroke where there are multiple modifiers and one key like CTRL-ALT-C where CTRL and ALT are the modifierKeys and C is the key.
146 | /// The flow is Modifiers KeyDown in order, Key Press, Modifiers KeyUp in reverse order.
147 | ///
148 | /// The list of modifier keys
149 | /// The key to simulate
150 | public IKeyboardSimulator ModifiedKeyStroke(IEnumerable modifierKeyCodes, VirtualKeyCode keyCode)
151 | {
152 | ModifiedKeyStroke(modifierKeyCodes, new[] {keyCode});
153 | return this;
154 | }
155 |
156 | ///
157 | /// Simulates a modified keystroke where there is one modifier and multiple keys like CTRL-K-C where CTRL is the modifierKey and K and C are the keys.
158 | /// The flow is Modifier KeyDown, Keys Press in order, Modifier KeyUp.
159 | ///
160 | /// The modifier key
161 | /// The list of keys to simulate
162 | public IKeyboardSimulator ModifiedKeyStroke(VirtualKeyCode modifierKey, IEnumerable keyCodes)
163 | {
164 | ModifiedKeyStroke(new [] {modifierKey}, keyCodes);
165 | return this;
166 | }
167 |
168 | ///
169 | /// Simulates a modified keystroke where there are multiple modifiers and multiple keys like CTRL-ALT-K-C where CTRL and ALT are the modifierKeys and K and C are the keys.
170 | /// The flow is Modifiers KeyDown in order, Keys Press in order, Modifiers KeyUp in reverse order.
171 | ///
172 | /// The list of modifier keys
173 | /// The list of keys to simulate
174 | public IKeyboardSimulator ModifiedKeyStroke(IEnumerable modifierKeyCodes, IEnumerable keyCodes)
175 | {
176 | var builder = new InputBuilder();
177 | ModifiersDown(builder, modifierKeyCodes);
178 | KeysPress(builder, keyCodes);
179 | ModifiersUp(builder, modifierKeyCodes);
180 |
181 | SendSimulatedInput(builder.ToArray());
182 | return this;
183 | }
184 |
185 | ///
186 | /// Calls the Win32 SendInput method with a stream of KeyDown and KeyUp messages in order to simulate uninterrupted text entry via the keyboard.
187 | ///
188 | /// The text to be simulated.
189 | public IKeyboardSimulator TextEntry(string text)
190 | {
191 | if (text.Length > UInt32.MaxValue / 2) throw new ArgumentException(string.Format("The text parameter is too long. It must be less than {0} characters.", UInt32.MaxValue / 2), "text");
192 | var inputList = new InputBuilder().AddCharacters(text).ToArray();
193 | SendSimulatedInput(inputList);
194 | return this;
195 | }
196 |
197 | ///
198 | /// Simulates a single character text entry via the keyboard.
199 | ///
200 | /// The unicode character to be simulated.
201 | public IKeyboardSimulator TextEntry(char character)
202 | {
203 | var inputList = new InputBuilder().AddCharacter(character).ToArray();
204 | SendSimulatedInput(inputList);
205 | return this;
206 | }
207 |
208 | ///
209 | /// Sleeps the executing thread to create a pause between simulated inputs.
210 | ///
211 | /// The number of milliseconds to wait.
212 | public IKeyboardSimulator Sleep(int millsecondsTimeout)
213 | {
214 | Thread.Sleep(millsecondsTimeout);
215 | return this;
216 | }
217 |
218 | ///
219 | /// Sleeps the executing thread to create a pause between simulated inputs.
220 | ///
221 | /// The time to wait.
222 | public IKeyboardSimulator Sleep(TimeSpan timeout)
223 | {
224 | Thread.Sleep(timeout);
225 | return this;
226 | }
227 | }
228 | }
--------------------------------------------------------------------------------
/WindowsInput/WindowsInputDeviceStateAdaptor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using WindowsInput.Native;
3 |
4 | namespace WindowsInput
5 | {
6 | ///
7 | /// An implementation of for Windows by calling the native and methods.
8 | ///
9 | public class WindowsInputDeviceStateAdaptor : IInputDeviceStateAdaptor
10 | {
11 |
12 | ///
13 | /// Determines whether the specified key is up or down by calling the GetKeyState function. (See: http://msdn.microsoft.com/en-us/library/ms646301(VS.85).aspx)
14 | ///
15 | /// The for the key.
16 | ///
17 | /// true if the key is down; otherwise, false.
18 | ///
19 | ///
20 | /// The key status returned from this function changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information.
21 | /// An application calls GetKeyState in response to a keyboard-input message. This function retrieves the state of the key when the input message was generated.
22 | /// To retrieve state information for all the virtual keys, use the GetKeyboardState function.
23 | /// An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for Bthe nVirtKey parameter. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as values for nVirtKey to distinguish between the left and right instances of those keys.
24 | /// VK_LSHIFT
25 | /// VK_RSHIFT
26 | /// VK_LCONTROL
27 | /// VK_RCONTROL
28 | /// VK_LMENU
29 | /// VK_RMENU
30 | ///
31 | /// These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.
32 | ///
33 | public bool IsKeyDown(VirtualKeyCode keyCode)
34 | {
35 | Int16 result = NativeMethods.GetKeyState((UInt16)keyCode);
36 | return (result < 0);
37 | }
38 |
39 | ///
40 | /// Determines whether the specified key is up or downby calling the function. (See: http://msdn.microsoft.com/en-us/library/ms646301(VS.85).aspx)
41 | ///
42 | /// The for the key.
43 | ///
44 | /// true if the key is up; otherwise, false.
45 | ///
46 | ///
47 | /// The key status returned from this function changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information.
48 | /// An application calls GetKeyState in response to a keyboard-input message. This function retrieves the state of the key when the input message was generated.
49 | /// To retrieve state information for all the virtual keys, use the GetKeyboardState function.
50 | /// An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for Bthe nVirtKey parameter. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as values for nVirtKey to distinguish between the left and right instances of those keys.
51 | /// VK_LSHIFT
52 | /// VK_RSHIFT
53 | /// VK_LCONTROL
54 | /// VK_RCONTROL
55 | /// VK_LMENU
56 | /// VK_RMENU
57 | ///
58 | /// These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.
59 | ///
60 | public bool IsKeyUp(VirtualKeyCode keyCode)
61 | {
62 | return !IsKeyDown(keyCode);
63 | }
64 |
65 | ///
66 | /// Determines whether the physical key is up or down at the time the function is called regardless of whether the application thread has read the keyboard event from the message pump by calling the function. (See: http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx)
67 | ///
68 | /// The for the key.
69 | ///
70 | /// true if the key is down; otherwise, false.
71 | ///
72 | ///
73 | /// The GetAsyncKeyState function works with mouse buttons. However, it checks on the state of the physical mouse buttons, not on the logical mouse buttons that the physical buttons are mapped to. For example, the call GetAsyncKeyState(VK_LBUTTON) always returns the state of the left physical mouse button, regardless of whether it is mapped to the left or right logical mouse button. You can determine the system's current mapping of physical mouse buttons to logical mouse buttons by calling
74 | /// Copy CodeGetSystemMetrics(SM_SWAPBUTTON) which returns TRUE if the mouse buttons have been swapped.
75 | ///
76 | /// Although the least significant bit of the return value indicates whether the key has been pressed since the last query, due to the pre-emptive multitasking nature of Windows, another application can call GetAsyncKeyState and receive the "recently pressed" bit instead of your application. The behavior of the least significant bit of the return value is retained strictly for compatibility with 16-bit Windows applications (which are non-preemptive) and should not be relied upon.
77 | ///
78 | /// You can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the vKey parameter. This gives the state of the SHIFT, CTRL, or ALT keys without distinguishing between left and right.
79 | ///
80 | /// Windows NT/2000/XP: You can use the following virtual-key code constants as values for vKey to distinguish between the left and right instances of those keys.
81 | ///
82 | /// Code Meaning
83 | /// VK_LSHIFT Left-shift key.
84 | /// VK_RSHIFT Right-shift key.
85 | /// VK_LCONTROL Left-control key.
86 | /// VK_RCONTROL Right-control key.
87 | /// VK_LMENU Left-menu key.
88 | /// VK_RMENU Right-menu key.
89 | ///
90 | /// These left- and right-distinguishing constants are only available when you call the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.
91 | ///
92 | public bool IsHardwareKeyDown(VirtualKeyCode keyCode)
93 | {
94 | var result = NativeMethods.GetAsyncKeyState((UInt16)keyCode);
95 | return (result < 0);
96 | }
97 |
98 | ///
99 | /// Determines whether the physical key is up or down at the time the function is called regardless of whether the application thread has read the keyboard event from the message pump by calling the function. (See: http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx)
100 | ///
101 | /// The for the key.
102 | ///
103 | /// true if the key is up; otherwise, false.
104 | ///
105 | ///
106 | /// The GetAsyncKeyState function works with mouse buttons. However, it checks on the state of the physical mouse buttons, not on the logical mouse buttons that the physical buttons are mapped to. For example, the call GetAsyncKeyState(VK_LBUTTON) always returns the state of the left physical mouse button, regardless of whether it is mapped to the left or right logical mouse button. You can determine the system's current mapping of physical mouse buttons to logical mouse buttons by calling
107 | /// Copy CodeGetSystemMetrics(SM_SWAPBUTTON) which returns TRUE if the mouse buttons have been swapped.
108 | ///
109 | /// Although the least significant bit of the return value indicates whether the key has been pressed since the last query, due to the pre-emptive multitasking nature of Windows, another application can call GetAsyncKeyState and receive the "recently pressed" bit instead of your application. The behavior of the least significant bit of the return value is retained strictly for compatibility with 16-bit Windows applications (which are non-preemptive) and should not be relied upon.
110 | ///
111 | /// You can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the vKey parameter. This gives the state of the SHIFT, CTRL, or ALT keys without distinguishing between left and right.
112 | ///
113 | /// Windows NT/2000/XP: You can use the following virtual-key code constants as values for vKey to distinguish between the left and right instances of those keys.
114 | ///
115 | /// Code Meaning
116 | /// VK_LSHIFT Left-shift key.
117 | /// VK_RSHIFT Right-shift key.
118 | /// VK_LCONTROL Left-control key.
119 | /// VK_RCONTROL Right-control key.
120 | /// VK_LMENU Left-menu key.
121 | /// VK_RMENU Right-menu key.
122 | ///
123 | /// These left- and right-distinguishing constants are only available when you call the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.
124 | ///
125 | public bool IsHardwareKeyUp(VirtualKeyCode keyCode)
126 | {
127 | return !IsHardwareKeyDown(keyCode);
128 | }
129 |
130 | ///
131 | /// Determines whether the toggling key is toggled on (in-effect) or not by calling the function. (See: http://msdn.microsoft.com/en-us/library/ms646301(VS.85).aspx)
132 | ///
133 | /// The for the key.
134 | ///
135 | /// true if the toggling key is toggled on (in-effect); otherwise, false.
136 | ///
137 | ///
138 | /// The key status returned from this function changes as a thread reads key messages from its message queue. The status does not reflect the interrupt-level state associated with the hardware. Use the GetAsyncKeyState function to retrieve that information.
139 | /// An application calls GetKeyState in response to a keyboard-input message. This function retrieves the state of the key when the input message was generated.
140 | /// To retrieve state information for all the virtual keys, use the GetKeyboardState function.
141 | /// An application can use the virtual-key code constants VK_SHIFT, VK_CONTROL, and VK_MENU as values for the nVirtKey parameter. This gives the status of the SHIFT, CTRL, or ALT keys without distinguishing between left and right. An application can also use the following virtual-key code constants as values for nVirtKey to distinguish between the left and right instances of those keys.
142 | /// VK_LSHIFT
143 | /// VK_RSHIFT
144 | /// VK_LCONTROL
145 | /// VK_RCONTROL
146 | /// VK_LMENU
147 | /// VK_RMENU
148 | ///
149 | /// These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions.
150 | ///
151 | public bool IsTogglingKeyInEffect(VirtualKeyCode keyCode)
152 | {
153 | Int16 result = NativeMethods.GetKeyState((UInt16)keyCode);
154 | return (result & 0x01) == 0x01;
155 | }
156 | }
157 | }
--------------------------------------------------------------------------------
/WindowsInput/MouseSimulator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading;
3 | using WindowsInput.Native;
4 |
5 | namespace WindowsInput
6 | {
7 | ///
8 | /// Implements the interface by calling the an to simulate Mouse gestures.
9 | ///
10 | public class MouseSimulator : IMouseSimulator
11 | {
12 | private const int MouseWheelClickSize = 120;
13 |
14 | private readonly IInputSimulator _inputSimulator;
15 |
16 | ///
17 | /// The instance of the to use for dispatching messages.
18 | ///
19 | private readonly IInputMessageDispatcher _messageDispatcher;
20 |
21 | ///
22 | /// Initializes a new instance of the class using an instance of a for dispatching messages.
23 | ///
24 | /// The that owns this instance.
25 | public MouseSimulator(IInputSimulator inputSimulator)
26 | {
27 | if (inputSimulator == null) throw new ArgumentNullException("inputSimulator");
28 |
29 | _inputSimulator = inputSimulator;
30 | _messageDispatcher = new WindowsInputMessageDispatcher();
31 | }
32 |
33 | ///
34 | /// Initializes a new instance of the class using the specified for dispatching messages.
35 | ///
36 | /// The that owns this instance.
37 | /// The to use for dispatching messages.
38 | /// If null is passed as the .
39 | internal MouseSimulator(IInputSimulator inputSimulator, IInputMessageDispatcher messageDispatcher)
40 | {
41 | if (inputSimulator == null)
42 | throw new ArgumentNullException("inputSimulator");
43 |
44 | if (messageDispatcher == null)
45 | throw new InvalidOperationException(
46 | string.Format("The {0} cannot operate with a null {1}. Please provide a valid {1} instance to use for dispatching {2} messages.",
47 | typeof(MouseSimulator).Name, typeof(IInputMessageDispatcher).Name, typeof(INPUT).Name));
48 |
49 | _inputSimulator = inputSimulator;
50 | _messageDispatcher = messageDispatcher;
51 | }
52 |
53 | ///
54 | /// Gets the instance for simulating Keyboard input.
55 | ///
56 | /// The instance.
57 | public IKeyboardSimulator Keyboard { get { return _inputSimulator.Keyboard; } }
58 |
59 | ///
60 | /// Sends the list of messages using the instance.
61 | ///
62 | /// The of messages to send.
63 | private void SendSimulatedInput(INPUT[] inputList)
64 | {
65 | _messageDispatcher.DispatchInput(inputList);
66 | }
67 |
68 | ///
69 | /// Simulates mouse movement by the specified distance measured as a delta from the current mouse location in pixels.
70 | ///
71 | /// The distance in pixels to move the mouse horizontally.
72 | /// The distance in pixels to move the mouse vertically.
73 | public IMouseSimulator MoveMouseBy(int pixelDeltaX, int pixelDeltaY)
74 | {
75 | var inputList = new InputBuilder().AddRelativeMouseMovement(pixelDeltaX, pixelDeltaY).ToArray();
76 | SendSimulatedInput(inputList);
77 | return this;
78 | }
79 |
80 | ///
81 | /// Simulates mouse movement to the specified location on the primary display device.
82 | ///
83 | /// The destination's absolute X-coordinate on the primary display device where 0 is the extreme left hand side of the display device and 65535 is the extreme right hand side of the display device.
84 | /// The destination's absolute Y-coordinate on the primary display device where 0 is the top of the display device and 65535 is the bottom of the display device.
85 | public IMouseSimulator MoveMouseTo(double absoluteX, double absoluteY)
86 | {
87 | var inputList = new InputBuilder().AddAbsoluteMouseMovement((int)Math.Truncate(absoluteX), (int)Math.Truncate(absoluteY)).ToArray();
88 | SendSimulatedInput(inputList);
89 | return this;
90 | }
91 |
92 | ///
93 | /// Simulates mouse movement to the specified location on the Virtual Desktop which includes all active displays.
94 | ///
95 | /// The destination's absolute X-coordinate on the virtual desktop where 0 is the left hand side of the virtual desktop and 65535 is the extreme right hand side of the virtual desktop.
96 | /// The destination's absolute Y-coordinate on the virtual desktop where 0 is the top of the virtual desktop and 65535 is the bottom of the virtual desktop.
97 | public IMouseSimulator MoveMouseToPositionOnVirtualDesktop(double absoluteX, double absoluteY)
98 | {
99 | var inputList = new InputBuilder().AddAbsoluteMouseMovementOnVirtualDesktop((int)Math.Truncate(absoluteX), (int)Math.Truncate(absoluteY)).ToArray();
100 | SendSimulatedInput(inputList);
101 | return this;
102 | }
103 |
104 | ///
105 | /// Simulates a mouse left button down gesture.
106 | ///
107 | public IMouseSimulator LeftButtonDown()
108 | {
109 | var inputList = new InputBuilder().AddMouseButtonDown(MouseButton.LeftButton).ToArray();
110 | SendSimulatedInput(inputList);
111 | return this;
112 | }
113 |
114 | ///
115 | /// Simulates a mouse left button up gesture.
116 | ///
117 | public IMouseSimulator LeftButtonUp()
118 | {
119 | var inputList = new InputBuilder().AddMouseButtonUp(MouseButton.LeftButton).ToArray();
120 | SendSimulatedInput(inputList);
121 | return this;
122 | }
123 |
124 | ///
125 | /// Simulates a mouse left-click gesture.
126 | ///
127 | public IMouseSimulator LeftButtonClick()
128 | {
129 | var inputList = new InputBuilder().AddMouseButtonClick(MouseButton.LeftButton).ToArray();
130 | SendSimulatedInput(inputList);
131 | return this;
132 | }
133 |
134 | ///
135 | /// Simulates a mouse left button double-click gesture.
136 | ///
137 | public IMouseSimulator LeftButtonDoubleClick()
138 | {
139 | var inputList = new InputBuilder().AddMouseButtonDoubleClick(MouseButton.LeftButton).ToArray();
140 | SendSimulatedInput(inputList);
141 | return this;
142 | }
143 |
144 | ///
145 | /// Simulates a mouse right button down gesture.
146 | ///
147 | public IMouseSimulator RightButtonDown()
148 | {
149 | var inputList = new InputBuilder().AddMouseButtonDown(MouseButton.RightButton).ToArray();
150 | SendSimulatedInput(inputList);
151 | return this;
152 | }
153 |
154 | ///
155 | /// Simulates a mouse right button up gesture.
156 | ///
157 | public IMouseSimulator RightButtonUp()
158 | {
159 | var inputList = new InputBuilder().AddMouseButtonUp(MouseButton.RightButton).ToArray();
160 | SendSimulatedInput(inputList);
161 | return this;
162 | }
163 |
164 | ///
165 | /// Simulates a mouse right button click gesture.
166 | ///
167 | public IMouseSimulator RightButtonClick()
168 | {
169 | var inputList = new InputBuilder().AddMouseButtonClick(MouseButton.RightButton).ToArray();
170 | SendSimulatedInput(inputList);
171 | return this;
172 | }
173 |
174 | ///
175 | /// Simulates a mouse right button double-click gesture.
176 | ///
177 | public IMouseSimulator RightButtonDoubleClick()
178 | {
179 | var inputList = new InputBuilder().AddMouseButtonDoubleClick(MouseButton.RightButton).ToArray();
180 | SendSimulatedInput(inputList);
181 | return this;
182 | }
183 |
184 | ///
185 | /// Simulates a mouse X button down gesture.
186 | ///
187 | /// The button id.
188 | public IMouseSimulator XButtonDown(int buttonId)
189 | {
190 | var inputList = new InputBuilder().AddMouseXButtonDown(buttonId).ToArray();
191 | SendSimulatedInput(inputList);
192 | return this;
193 | }
194 |
195 | ///
196 | /// Simulates a mouse X button up gesture.
197 | ///
198 | /// The button id.
199 | public IMouseSimulator XButtonUp(int buttonId)
200 | {
201 | var inputList = new InputBuilder().AddMouseXButtonUp(buttonId).ToArray();
202 | SendSimulatedInput(inputList);
203 | return this;
204 | }
205 |
206 | ///
207 | /// Simulates a mouse X button click gesture.
208 | ///
209 | /// The button id.
210 | public IMouseSimulator XButtonClick(int buttonId)
211 | {
212 | var inputList = new InputBuilder().AddMouseXButtonClick(buttonId).ToArray();
213 | SendSimulatedInput(inputList);
214 | return this;
215 | }
216 |
217 | ///
218 | /// Simulates a mouse X button double-click gesture.
219 | ///
220 | /// The button id.
221 | public IMouseSimulator XButtonDoubleClick(int buttonId)
222 | {
223 | var inputList = new InputBuilder().AddMouseXButtonDoubleClick(buttonId).ToArray();
224 | SendSimulatedInput(inputList);
225 | return this;
226 | }
227 |
228 | ///
229 | /// Simulates mouse vertical wheel scroll gesture.
230 | ///
231 | /// The amount to scroll in clicks. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user.
232 | public IMouseSimulator VerticalScroll(int scrollAmountInClicks)
233 | {
234 | var inputList = new InputBuilder().AddMouseVerticalWheelScroll(scrollAmountInClicks * MouseWheelClickSize).ToArray();
235 | SendSimulatedInput(inputList);
236 | return this;
237 | }
238 |
239 | ///
240 | /// Simulates a mouse horizontal wheel scroll gesture. Supported by Windows Vista and later.
241 | ///
242 | /// The amount to scroll in clicks. A positive value indicates that the wheel was rotated to the right; a negative value indicates that the wheel was rotated to the left.
243 | public IMouseSimulator HorizontalScroll(int scrollAmountInClicks)
244 | {
245 | var inputList = new InputBuilder().AddMouseHorizontalWheelScroll(scrollAmountInClicks * MouseWheelClickSize).ToArray();
246 | SendSimulatedInput(inputList);
247 | return this;
248 | }
249 |
250 | ///
251 | /// Sleeps the executing thread to create a pause between simulated inputs.
252 | ///
253 | /// The number of milliseconds to wait.
254 | public IMouseSimulator Sleep(int millsecondsTimeout)
255 | {
256 | Thread.Sleep(millsecondsTimeout);
257 | return this;
258 | }
259 |
260 | ///
261 | /// Sleeps the executing thread to create a pause between simulated inputs.
262 | ///
263 | /// The time to wait.
264 | public IMouseSimulator Sleep(TimeSpan timeout)
265 | {
266 | Thread.Sleep(timeout);
267 | return this;
268 | }
269 | }
270 | }
--------------------------------------------------------------------------------
/WindowsInput.Tests/UnicodeText/UnicodeTextTests.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net;
3 | using System.Threading;
4 | using System.Threading.Tasks;
5 | using HtmlAgilityPack;
6 | using NUnit.Framework;
7 |
8 | namespace WindowsInput.Tests.UnicodeText
9 | {
10 | [TestFixture]
11 | public class UnicodeTextTests
12 | {
13 | private TestCaseData[] _unicodeTestCases;
14 | public TestCaseData[] UnicodeTestCases
15 | {
16 | get
17 | {
18 | if (_unicodeTestCases == null)
19 | {
20 | var ranges = GetUnicodeRanges();
21 | _unicodeTestCases = Array.ConvertAll(ranges, BuildTestCase);
22 | }
23 | return _unicodeTestCases;
24 | }
25 | }
26 |
27 | private TestCaseData BuildTestCase(UnicodeRange input)
28 | {
29 | return new TestCaseData(input).SetName(input.Name);
30 | }
31 |
32 | [Test]
33 | [Explicit]
34 | [TestCaseSource("UnicodeTestCases")]
35 | public void TestUnicodeRanges(UnicodeRange range)
36 | {
37 | // ReSharper disable AccessToDisposedClosure
38 | using (var form = new UnicodeTestForm
39 | {
40 | Expected = range.Characters
41 | })
42 | {
43 | var ready = false;
44 | var formTask = Task.Factory.StartNew(
45 | () =>
46 | {
47 | form.Shown += (x, y) => ready = true;
48 | form.ShowDialog();
49 | }, TaskCreationOptions.LongRunning);
50 |
51 | var simTask = Task.Factory.StartNew(
52 | () =>
53 | {
54 | while (!ready)
55 | {
56 | Thread.Sleep(250);
57 | }
58 | var sim = new InputSimulator();
59 | sim.Keyboard.TextEntry(range.Characters);
60 | while (form.Recieved != form.Expected)
61 | {
62 | Thread.Sleep(500);
63 | }
64 | form.Close();
65 | }, TaskCreationOptions.LongRunning);
66 |
67 | Task.WaitAll(new[] {formTask, simTask}, TimeSpan.FromSeconds(60));
68 | Assert.That(form.Recieved, Is.EqualTo(form.Expected));
69 | }
70 | // ReSharper restore AccessToDisposedClosure
71 | }
72 |
73 | [Test]
74 | [Explicit]
75 | public void GetCharacterRanges()
76 | {
77 | using (var client = new WebClient())
78 | {
79 | var html = client.DownloadString("http://jrgraphix.net/r/Unicode/");
80 | var htmlDoc = new HtmlDocument();
81 | htmlDoc.LoadHtml(html);
82 | foreach (var link in htmlDoc.DocumentNode.SelectNodes("//a[@href]"))
83 | {
84 | var a = link.GetAttributeValue("href", "unknown");
85 | if (a.Contains("Unicode"))
86 | {
87 | a = "0x" + a.Replace("/r/Unicode/", "").Replace("-", ", 0x") + "),";
88 | Console.WriteLine("new UnicodeRange(\"" + link.InnerText + "\", " + a);
89 | }
90 | }
91 | }
92 | }
93 |
94 | public UnicodeRange[] GetUnicodeRanges()
95 | {
96 | return new[]
97 | {
98 | new UnicodeRange("Basic Latin", 0x0020, 0x007F),
99 | new UnicodeRange("Block Elements", 0x2580, 0x259F),
100 | new UnicodeRange("Latin-1 Supplement", 0x00A0, 0x00FF),
101 | new UnicodeRange("Geometric Shapes", 0x25A0, 0x25FF),
102 | new UnicodeRange("Latin Extended-A", 0x0100, 0x017F),
103 | new UnicodeRange("Miscellaneous Symbols", 0x2600, 0x26FF),
104 | new UnicodeRange("Latin Extended-B", 0x0180, 0x024F),
105 | new UnicodeRange("Dingbats", 0x2700, 0x27BF),
106 | new UnicodeRange("IPA Extensions", 0x0250, 0x02AF),
107 | new UnicodeRange("Miscellaneous Mathematical Symbols-A", 0x27C0, 0x27EF),
108 | new UnicodeRange("Spacing Modifier Letters", 0x02B0, 0x02FF),
109 | new UnicodeRange("Supplemental Arrows-A", 0x27F0, 0x27FF),
110 | new UnicodeRange("Combining Diacritical Marks", 0x0300, 0x036F),
111 | new UnicodeRange("Braille Patterns", 0x2800, 0x28FF),
112 | new UnicodeRange("Greek and Coptic", 0x0370, 0x03FF),
113 | new UnicodeRange("Supplemental Arrows-B", 0x2900, 0x297F),
114 | new UnicodeRange("Cyrillic", 0x0400, 0x04FF),
115 | new UnicodeRange("Miscellaneous Mathematical Symbols-B", 0x2980, 0x29FF),
116 | new UnicodeRange("Cyrillic Supplementary", 0x0500, 0x052F),
117 | new UnicodeRange("Supplemental Mathematical Operators", 0x2A00, 0x2AFF),
118 | new UnicodeRange("Armenian", 0x0530, 0x058F),
119 | new UnicodeRange("Miscellaneous Symbols and Arrows", 0x2B00, 0x2BFF),
120 | new UnicodeRange("Hebrew", 0x0590, 0x05FF),
121 | new UnicodeRange("CJK Radicals Supplement", 0x2E80, 0x2EFF),
122 | new UnicodeRange("Arabic", 0x0600, 0x06FF),
123 | new UnicodeRange("Kangxi Radicals", 0x2F00, 0x2FDF),
124 | new UnicodeRange("Syriac", 0x0700, 0x074F),
125 | new UnicodeRange("Ideographic Description Characters", 0x2FF0, 0x2FFF),
126 | new UnicodeRange("Thaana", 0x0780, 0x07BF),
127 | new UnicodeRange("CJK Symbols and Punctuation", 0x3000, 0x303F),
128 | new UnicodeRange("Devanagari", 0x0900, 0x097F),
129 | new UnicodeRange("Hiragana", 0x3040, 0x309F),
130 | new UnicodeRange("Bengali", 0x0980, 0x09FF),
131 | new UnicodeRange("Katakana", 0x30A0, 0x30FF),
132 | new UnicodeRange("Gurmukhi", 0x0A00, 0x0A7F),
133 | new UnicodeRange("Bopomofo", 0x3100, 0x312F),
134 | new UnicodeRange("Gujarati", 0x0A80, 0x0AFF),
135 | new UnicodeRange("Hangul Compatibility Jamo", 0x3130, 0x318F),
136 | new UnicodeRange("Oriya", 0x0B00, 0x0B7F),
137 | new UnicodeRange("Kanbun", 0x3190, 0x319F),
138 | new UnicodeRange("Tamil", 0x0B80, 0x0BFF),
139 | new UnicodeRange("Bopomofo Extended", 0x31A0, 0x31BF),
140 | new UnicodeRange("Telugu", 0x0C00, 0x0C7F),
141 | new UnicodeRange("Katakana Phonetic Extensions", 0x31F0, 0x31FF),
142 | new UnicodeRange("Kannada", 0x0C80, 0x0CFF),
143 | new UnicodeRange("Enclosed CJK Letters and Months", 0x3200, 0x32FF),
144 | new UnicodeRange("Malayalam", 0x0D00, 0x0D7F),
145 | new UnicodeRange("CJK Compatibility", 0x3300, 0x33FF),
146 | new UnicodeRange("Sinhala", 0x0D80, 0x0DFF),
147 | new UnicodeRange("CJK Unified Ideographs Extension A", 0x3400, 0x4DBF),
148 | new UnicodeRange("Thai", 0x0E00, 0x0E7F),
149 | new UnicodeRange("Yijing Hexagram Symbols", 0x4DC0, 0x4DFF),
150 | new UnicodeRange("Lao", 0x0E80, 0x0EFF),
151 | new UnicodeRange("CJK Unified Ideographs", 0x4E00, 0x9FFF),
152 | new UnicodeRange("Tibetan", 0x0F00, 0x0FFF),
153 | new UnicodeRange("Yi Syllables", 0xA000, 0xA48F),
154 | new UnicodeRange("Myanmar", 0x1000, 0x109F),
155 | new UnicodeRange("Yi Radicals", 0xA490, 0xA4CF),
156 | new UnicodeRange("Georgian", 0x10A0, 0x10FF),
157 | new UnicodeRange("Hangul Syllables", 0xAC00, 0xD7AF),
158 | new UnicodeRange("Hangul Jamo", 0x1100, 0x11FF),
159 | new UnicodeRange("High Surrogates", 0xD800, 0xDB7F),
160 | new UnicodeRange("Ethiopic", 0x1200, 0x137F),
161 | new UnicodeRange("High Private Use Surrogates", 0xDB80, 0xDBFF),
162 | new UnicodeRange("Cherokee", 0x13A0, 0x13FF),
163 | new UnicodeRange("Low Surrogates", 0xDC00, 0xDFFF),
164 | new UnicodeRange("Unified Canadian Aboriginal Syllabics", 0x1400, 0x167F),
165 | new UnicodeRange("Private Use Area", 0xE000, 0xF8FF),
166 | new UnicodeRange("Ogham", 0x1680, 0x169F),
167 | new UnicodeRange("CJK Compatibility Ideographs", 0xF900, 0xFAFF),
168 | new UnicodeRange("Runic", 0x16A0, 0x16FF),
169 | new UnicodeRange("Alphabetic Presentation Forms", 0xFB00, 0xFB4F),
170 | new UnicodeRange("Tagalog", 0x1700, 0x171F),
171 | new UnicodeRange("Arabic Presentation Forms-A", 0xFB50, 0xFDFF),
172 | new UnicodeRange("Hanunoo", 0x1720, 0x173F),
173 | new UnicodeRange("Variation Selectors", 0xFE00, 0xFE0F),
174 | new UnicodeRange("Buhid", 0x1740, 0x175F),
175 | new UnicodeRange("Combining Half Marks", 0xFE20, 0xFE2F),
176 | new UnicodeRange("Tagbanwa", 0x1760, 0x177F),
177 | new UnicodeRange("CJK Compatibility Forms", 0xFE30, 0xFE4F),
178 | new UnicodeRange("Khmer", 0x1780, 0x17FF),
179 | new UnicodeRange("Small Form Variants", 0xFE50, 0xFE6F),
180 | new UnicodeRange("Mongolian", 0x1800, 0x18AF),
181 | new UnicodeRange("Arabic Presentation Forms-B", 0xFE70, 0xFEFF),
182 | new UnicodeRange("Limbu", 0x1900, 0x194F),
183 | new UnicodeRange("Halfwidth and Fullwidth Forms", 0xFF00, 0xFFEF),
184 | new UnicodeRange("Tai Le", 0x1950, 0x197F),
185 | new UnicodeRange("Specials", 0xFFF0, 0xFFFF),
186 | new UnicodeRange("Khmer Symbols", 0x19E0, 0x19FF),
187 | new UnicodeRange("Linear B Syllabary", 0x10000, 0x1007F),
188 | new UnicodeRange("Phonetic Extensions", 0x1D00, 0x1D7F),
189 | new UnicodeRange("Linear B Ideograms", 0x10080, 0x100FF),
190 | new UnicodeRange("Latin Extended Additional", 0x1E00, 0x1EFF),
191 | new UnicodeRange("Aegean Numbers", 0x10100, 0x1013F),
192 | new UnicodeRange("Greek Extended", 0x1F00, 0x1FFF),
193 | new UnicodeRange("Old Italic", 0x10300, 0x1032F),
194 | new UnicodeRange("General Punctuation", 0x2000, 0x206F),
195 | new UnicodeRange("Gothic", 0x10330, 0x1034F),
196 | new UnicodeRange("Superscripts and Subscripts", 0x2070, 0x209F),
197 | new UnicodeRange("Ugaritic", 0x10380, 0x1039F),
198 | new UnicodeRange("Currency Symbols", 0x20A0, 0x20CF),
199 | new UnicodeRange("Deseret", 0x10400, 0x1044F),
200 | new UnicodeRange("Combining Diacritical Marks for Symbols", 0x20D0, 0x20FF),
201 | new UnicodeRange("Shavian", 0x10450, 0x1047F),
202 | new UnicodeRange("Letterlike Symbols", 0x2100, 0x214F),
203 | new UnicodeRange("Osmanya", 0x10480, 0x104AF),
204 | new UnicodeRange("Number Forms", 0x2150, 0x218F),
205 | new UnicodeRange("Cypriot Syllabary", 0x10800, 0x1083F),
206 | new UnicodeRange("Arrows", 0x2190, 0x21FF),
207 | new UnicodeRange("Byzantine Musical Symbols", 0x1D000, 0x1D0FF),
208 | new UnicodeRange("Mathematical Operators", 0x2200, 0x22FF),
209 | new UnicodeRange("Musical Symbols", 0x1D100, 0x1D1FF),
210 | new UnicodeRange("Miscellaneous Technical", 0x2300, 0x23FF),
211 | new UnicodeRange("Tai Xuan Jing Symbols", 0x1D300, 0x1D35F),
212 | new UnicodeRange("Control Pictures", 0x2400, 0x243F),
213 | new UnicodeRange("Mathematical Alphanumeric Symbols", 0x1D400, 0x1D7FF),
214 | new UnicodeRange("Optical Character Recognition", 0x2440, 0x245F),
215 | new UnicodeRange("CJK Unified Ideographs Extension B", 0x20000, 0x2A6DF),
216 | new UnicodeRange("Enclosed Alphanumerics", 0x2460, 0x24FF),
217 | new UnicodeRange("CJK Compatibility Ideographs Supplement", 0x2F800, 0x2FA1F),
218 | new UnicodeRange("Box Drawing", 0x2500, 0x257F),
219 | new UnicodeRange("Tags", 0xE0000, 0xE007F)
220 | };
221 | }
222 | }
223 | }
--------------------------------------------------------------------------------
/WindowsInput/InputBuilder.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using WindowsInput.Native;
5 |
6 | namespace WindowsInput
7 | {
8 | ///
9 | /// A helper class for building a list of messages ready to be sent to the native Windows API.
10 | ///
11 | internal class InputBuilder : IEnumerable
12 | {
13 | ///
14 | /// The public list of messages being built by this instance.
15 | ///
16 | private readonly List _inputList;
17 |
18 | ///
19 | /// Initializes a new instance of the class.
20 | ///
21 | public InputBuilder()
22 | {
23 | _inputList = new List();
24 | }
25 |
26 | ///
27 | /// Returns the list of messages as a of messages.
28 | ///
29 | /// The of messages.
30 | public INPUT[] ToArray()
31 | {
32 | return _inputList.ToArray();
33 | }
34 |
35 | ///
36 | /// Returns an enumerator that iterates through the list of messages.
37 | ///
38 | ///
39 | /// A that can be used to iterate through the list of messages.
40 | ///
41 | /// 1
42 | public IEnumerator GetEnumerator()
43 | {
44 | return _inputList.GetEnumerator();
45 | }
46 |
47 | ///
48 | /// Returns an enumerator that iterates through the list of messages.
49 | ///
50 | ///
51 | /// An object that can be used to iterate through the list of messages.
52 | ///
53 | /// 2
54 | IEnumerator IEnumerable.GetEnumerator()
55 | {
56 | return GetEnumerator();
57 | }
58 |
59 | ///
60 | /// Gets the at the specified position.
61 | ///
62 | /// The message at the specified position.
63 | public INPUT this[int position]
64 | {
65 | get
66 | {
67 | return _inputList[position];
68 | }
69 | }
70 |
71 | ///
72 | /// Determines if the is an ExtendedKey
73 | ///
74 | /// The key code.
75 | /// true if the key code is an extended key; otherwise, false.
76 | ///
77 | /// The extended keys consist of the ALT and CTRL keys on the right-hand side of the keyboard; the INS, DEL, HOME, END, PAGE UP, PAGE DOWN, and arrow keys in the clusters to the left of the numeric keypad; the NUM LOCK key; the BREAK (CTRL+PAUSE) key; the PRINT SCRN key; and the divide (/) and ENTER keys in the numeric keypad.
78 | ///
79 | /// See http://msdn.microsoft.com/en-us/library/ms646267(v=vs.85).aspx Section "Extended-Key Flag"
80 | ///
81 | public static bool IsExtendedKey(VirtualKeyCode keyCode)
82 | {
83 | if (keyCode == VirtualKeyCode.MENU ||
84 | keyCode == VirtualKeyCode.LMENU ||
85 | keyCode == VirtualKeyCode.RMENU ||
86 | keyCode == VirtualKeyCode.CONTROL ||
87 | keyCode == VirtualKeyCode.RCONTROL ||
88 | keyCode == VirtualKeyCode.INSERT ||
89 | keyCode == VirtualKeyCode.DELETE ||
90 | keyCode == VirtualKeyCode.HOME ||
91 | keyCode == VirtualKeyCode.END ||
92 | keyCode == VirtualKeyCode.PRIOR ||
93 | keyCode == VirtualKeyCode.NEXT ||
94 | keyCode == VirtualKeyCode.RIGHT ||
95 | keyCode == VirtualKeyCode.UP ||
96 | keyCode == VirtualKeyCode.LEFT ||
97 | keyCode == VirtualKeyCode.DOWN ||
98 | keyCode == VirtualKeyCode.NUMLOCK ||
99 | keyCode == VirtualKeyCode.CANCEL ||
100 | keyCode == VirtualKeyCode.SNAPSHOT ||
101 | keyCode == VirtualKeyCode.DIVIDE)
102 | {
103 | return true;
104 | }
105 | else
106 | {
107 | return false;
108 | }
109 | }
110 |
111 | ///
112 | /// Adds a key down to the list of messages.
113 | ///
114 | /// The .
115 | /// This instance.
116 | public InputBuilder AddKeyDown(VirtualKeyCode keyCode)
117 | {
118 | var down =
119 | new INPUT
120 | {
121 | Type = (UInt32) InputType.Keyboard,
122 | Data =
123 | {
124 | Keyboard =
125 | new KEYBDINPUT
126 | {
127 | KeyCode = (UInt16) keyCode,
128 | Scan = (UInt16)(NativeMethods.MapVirtualKey((UInt32)keyCode, 0) & 0xFFU),
129 | Flags = IsExtendedKey(keyCode) ? (UInt32) KeyboardFlag.ExtendedKey : 0,
130 | Time = 0,
131 | ExtraInfo = IntPtr.Zero
132 | }
133 | }
134 | };
135 |
136 | _inputList.Add(down);
137 | return this;
138 | }
139 |
140 | ///
141 | /// Adds a key up to the list of messages.
142 | ///
143 | /// The .
144 | /// This instance.
145 | public InputBuilder AddKeyUp(VirtualKeyCode keyCode)
146 | {
147 | var up =
148 | new INPUT
149 | {
150 | Type = (UInt32) InputType.Keyboard,
151 | Data =
152 | {
153 | Keyboard =
154 | new KEYBDINPUT
155 | {
156 | KeyCode = (UInt16) keyCode,
157 | Scan = (UInt16)(NativeMethods.MapVirtualKey((UInt32)keyCode, 0) & 0xFFU),
158 | Flags = (UInt32) (IsExtendedKey(keyCode)
159 | ? KeyboardFlag.KeyUp | KeyboardFlag.ExtendedKey
160 | : KeyboardFlag.KeyUp),
161 | Time = 0,
162 | ExtraInfo = IntPtr.Zero
163 | }
164 | }
165 | };
166 |
167 | _inputList.Add(up);
168 | return this;
169 | }
170 |
171 | ///
172 | /// Adds a key press to the list of messages which is equivalent to a key down followed by a key up.
173 | ///
174 | /// The .
175 | /// This instance.
176 | public InputBuilder AddKeyPress(VirtualKeyCode keyCode)
177 | {
178 | AddKeyDown(keyCode);
179 | AddKeyUp(keyCode);
180 | return this;
181 | }
182 |
183 | ///
184 | /// Adds the character to the list of messages.
185 | ///
186 | /// The to be added to the list of messages.
187 | /// This instance.
188 | public InputBuilder AddCharacter(char character)
189 | {
190 | UInt16 scanCode = character;
191 |
192 | var down = new INPUT
193 | {
194 | Type = (UInt32)InputType.Keyboard,
195 | Data =
196 | {
197 | Keyboard =
198 | new KEYBDINPUT
199 | {
200 | KeyCode = 0,
201 | Scan = scanCode,
202 | Flags = (UInt32)KeyboardFlag.Unicode,
203 | Time = 0,
204 | ExtraInfo = IntPtr.Zero
205 | }
206 | }
207 | };
208 |
209 | var up = new INPUT
210 | {
211 | Type = (UInt32)InputType.Keyboard,
212 | Data =
213 | {
214 | Keyboard =
215 | new KEYBDINPUT
216 | {
217 | KeyCode = 0,
218 | Scan = scanCode,
219 | Flags =
220 | (UInt32)(KeyboardFlag.KeyUp | KeyboardFlag.Unicode),
221 | Time = 0,
222 | ExtraInfo = IntPtr.Zero
223 | }
224 | }
225 | };
226 |
227 | // Handle extended keys:
228 | // If the scan code is preceded by a prefix byte that has the value 0xE0 (224),
229 | // we need to include the KEYEVENTF_EXTENDEDKEY flag in the Flags property.
230 | if ((scanCode & 0xFF00) == 0xE000)
231 | {
232 | down.Data.Keyboard.Flags |= (UInt32)KeyboardFlag.ExtendedKey;
233 | up.Data.Keyboard.Flags |= (UInt32)KeyboardFlag.ExtendedKey;
234 | }
235 |
236 | _inputList.Add(down);
237 | _inputList.Add(up);
238 | return this;
239 | }
240 |
241 | ///
242 | /// Adds all of the characters in the specified of .
243 | ///
244 | /// The characters to add.
245 | /// This instance.
246 | public InputBuilder AddCharacters(IEnumerable characters)
247 | {
248 | foreach (var character in characters)
249 | {
250 | AddCharacter(character);
251 | }
252 | return this;
253 | }
254 |
255 | ///
256 | /// Adds the characters in the specified .
257 | ///
258 | /// The string of to add.
259 | /// This instance.
260 | public InputBuilder AddCharacters(string characters)
261 | {
262 | return AddCharacters(characters.ToCharArray());
263 | }
264 |
265 | ///
266 | /// Moves the mouse relative to its current position.
267 | ///
268 | ///
269 | ///
270 | /// This instance.
271 | public InputBuilder AddRelativeMouseMovement(int x, int y)
272 | {
273 | var movement = new INPUT { Type = (UInt32)InputType.Mouse };
274 | movement.Data.Mouse.Flags = (UInt32)MouseFlag.Move;
275 | movement.Data.Mouse.X = x;
276 | movement.Data.Mouse.Y = y;
277 |
278 | _inputList.Add(movement);
279 |
280 | return this;
281 | }
282 |
283 | ///
284 | /// Move the mouse to an absolute position.
285 | ///
286 | ///
287 | ///
288 | /// This instance.
289 | public InputBuilder AddAbsoluteMouseMovement(int absoluteX, int absoluteY)
290 | {
291 | var movement = new INPUT { Type = (UInt32)InputType.Mouse };
292 | movement.Data.Mouse.Flags = (UInt32)(MouseFlag.Move | MouseFlag.Absolute);
293 | movement.Data.Mouse.X = absoluteX;
294 | movement.Data.Mouse.Y = absoluteY;
295 |
296 | _inputList.Add(movement);
297 |
298 | return this;
299 | }
300 |
301 | ///
302 | /// Move the mouse to the absolute position on the virtual desktop.
303 | ///
304 | ///
305 | ///
306 | /// This instance.
307 | public InputBuilder AddAbsoluteMouseMovementOnVirtualDesktop(int absoluteX, int absoluteY)
308 | {
309 | var movement = new INPUT { Type = (UInt32)InputType.Mouse };
310 | movement.Data.Mouse.Flags = (UInt32)(MouseFlag.Move | MouseFlag.Absolute | MouseFlag.VirtualDesk);
311 | movement.Data.Mouse.X = absoluteX;
312 | movement.Data.Mouse.Y = absoluteY;
313 |
314 | _inputList.Add(movement);
315 |
316 | return this;
317 | }
318 |
319 | ///
320 | /// Adds a mouse button down for the specified button.
321 | ///
322 | ///
323 | /// This instance.
324 | public InputBuilder AddMouseButtonDown(MouseButton button)
325 | {
326 | var buttonDown = new INPUT { Type = (UInt32)InputType.Mouse };
327 | buttonDown.Data.Mouse.Flags = (UInt32)ToMouseButtonDownFlag(button);
328 |
329 | _inputList.Add(buttonDown);
330 |
331 | return this;
332 | }
333 |
334 | ///
335 | /// Adds a mouse button down for the specified button.
336 | ///
337 | ///
338 | /// This instance.
339 | public InputBuilder AddMouseXButtonDown(int xButtonId)
340 | {
341 | var buttonDown = new INPUT { Type = (UInt32)InputType.Mouse };
342 | buttonDown.Data.Mouse.Flags = (UInt32)MouseFlag.XDown;
343 | buttonDown.Data.Mouse.MouseData = (UInt32)xButtonId;
344 | _inputList.Add(buttonDown);
345 |
346 | return this;
347 | }
348 |
349 | ///
350 | /// Adds a mouse button up for the specified button.
351 | ///
352 | ///
353 | /// This instance.
354 | public InputBuilder AddMouseButtonUp(MouseButton button)
355 | {
356 | var buttonUp = new INPUT { Type = (UInt32)InputType.Mouse };
357 | buttonUp.Data.Mouse.Flags = (UInt32)ToMouseButtonUpFlag(button);
358 | _inputList.Add(buttonUp);
359 |
360 | return this;
361 | }
362 |
363 | ///
364 | /// Adds a mouse button up for the specified button.
365 | ///
366 | ///
367 | /// This instance.
368 | public InputBuilder AddMouseXButtonUp(int xButtonId)
369 | {
370 | var buttonUp = new INPUT { Type = (UInt32)InputType.Mouse };
371 | buttonUp.Data.Mouse.Flags = (UInt32)MouseFlag.XUp;
372 | buttonUp.Data.Mouse.MouseData = (UInt32)xButtonId;
373 | _inputList.Add(buttonUp);
374 |
375 | return this;
376 | }
377 |
378 | ///
379 | /// Adds a single click of the specified button.
380 | ///
381 | ///
382 | /// This instance.
383 | public InputBuilder AddMouseButtonClick(MouseButton button)
384 | {
385 | return AddMouseButtonDown(button).AddMouseButtonUp(button);
386 | }
387 |
388 | ///
389 | /// Adds a single click of the specified button.
390 | ///
391 | ///
392 | /// This instance.
393 | public InputBuilder AddMouseXButtonClick(int xButtonId)
394 | {
395 | return AddMouseXButtonDown(xButtonId).AddMouseXButtonUp(xButtonId);
396 | }
397 |
398 | ///
399 | /// Adds a double click of the specified button.
400 | ///
401 | ///
402 | /// This instance.
403 | public InputBuilder AddMouseButtonDoubleClick(MouseButton button)
404 | {
405 | return AddMouseButtonClick(button).AddMouseButtonClick(button);
406 | }
407 |
408 | ///
409 | /// Adds a double click of the specified button.
410 | ///
411 | ///
412 | /// This instance.
413 | public InputBuilder AddMouseXButtonDoubleClick(int xButtonId)
414 | {
415 | return AddMouseXButtonClick(xButtonId).AddMouseXButtonClick(xButtonId);
416 | }
417 |
418 | ///
419 | /// Scroll the vertical mouse wheel by the specified amount.
420 | ///
421 | ///
422 | /// This instance.
423 | public InputBuilder AddMouseVerticalWheelScroll(int scrollAmount)
424 | {
425 | var scroll = new INPUT { Type = (UInt32)InputType.Mouse };
426 | scroll.Data.Mouse.Flags = (UInt32)MouseFlag.VerticalWheel;
427 | scroll.Data.Mouse.MouseData = (UInt32)scrollAmount;
428 |
429 | _inputList.Add(scroll);
430 |
431 | return this;
432 | }
433 |
434 | ///
435 | /// Scroll the horizontal mouse wheel by the specified amount.
436 | ///
437 | ///
438 | /// This instance.
439 | public InputBuilder AddMouseHorizontalWheelScroll(int scrollAmount)
440 | {
441 | var scroll = new INPUT { Type = (UInt32)InputType.Mouse };
442 | scroll.Data.Mouse.Flags = (UInt32)MouseFlag.HorizontalWheel;
443 | scroll.Data.Mouse.MouseData = (UInt32)scrollAmount;
444 |
445 | _inputList.Add(scroll);
446 |
447 | return this;
448 | }
449 |
450 | private static MouseFlag ToMouseButtonDownFlag(MouseButton button)
451 | {
452 | switch (button)
453 | {
454 | case MouseButton.LeftButton:
455 | return MouseFlag.LeftDown;
456 |
457 | case MouseButton.MiddleButton:
458 | return MouseFlag.MiddleDown;
459 |
460 | case MouseButton.RightButton:
461 | return MouseFlag.RightDown;
462 |
463 | default:
464 | return MouseFlag.LeftDown;
465 | }
466 | }
467 |
468 | private static MouseFlag ToMouseButtonUpFlag(MouseButton button)
469 | {
470 | switch (button)
471 | {
472 | case MouseButton.LeftButton:
473 | return MouseFlag.LeftUp;
474 |
475 | case MouseButton.MiddleButton:
476 | return MouseFlag.MiddleUp;
477 |
478 | case MouseButton.RightButton:
479 | return MouseFlag.RightUp;
480 |
481 | default:
482 | return MouseFlag.LeftUp;
483 | }
484 | }
485 | }
486 | }
--------------------------------------------------------------------------------
/WindowsInput/Native/VirtualKeyCode.cs:
--------------------------------------------------------------------------------
1 | namespace WindowsInput.Native
2 | {
3 | ///
4 | /// The list of VirtualKeyCodes (see: http://msdn.microsoft.com/en-us/library/ms645540(VS.85).aspx)
5 | ///
6 | public enum VirtualKeyCode //: UInt16
7 | {
8 | ///
9 | /// Left mouse button
10 | ///
11 | LBUTTON = 0x01,
12 |
13 | ///
14 | /// Right mouse button
15 | ///
16 | RBUTTON = 0x02,
17 |
18 | ///
19 | /// Control-break processing
20 | ///
21 | CANCEL = 0x03,
22 |
23 | ///
24 | /// Middle mouse button (three-button mouse) - NOT contiguous with LBUTTON and RBUTTON
25 | ///
26 | MBUTTON = 0x04,
27 |
28 | ///
29 | /// Windows 2000/XP: X1 mouse button - NOT contiguous with LBUTTON and RBUTTON
30 | ///
31 | XBUTTON1 = 0x05,
32 |
33 | ///
34 | /// Windows 2000/XP: X2 mouse button - NOT contiguous with LBUTTON and RBUTTON
35 | ///
36 | XBUTTON2 = 0x06,
37 |
38 | // 0x07 : Undefined
39 |
40 | ///
41 | /// BACKSPACE key
42 | ///
43 | BACK = 0x08,
44 |
45 | ///
46 | /// TAB key
47 | ///
48 | TAB = 0x09,
49 |
50 | // 0x0A - 0x0B : Reserved
51 |
52 | ///
53 | /// CLEAR key
54 | ///
55 | CLEAR = 0x0C,
56 |
57 | ///
58 | /// ENTER key
59 | ///
60 | RETURN = 0x0D,
61 |
62 | // 0x0E - 0x0F : Undefined
63 |
64 | ///
65 | /// SHIFT key
66 | ///
67 | SHIFT = 0x10,
68 |
69 | ///
70 | /// CTRL key
71 | ///
72 | CONTROL = 0x11,
73 |
74 | ///
75 | /// ALT key
76 | ///
77 | MENU = 0x12,
78 |
79 | ///
80 | /// PAUSE key
81 | ///
82 | PAUSE = 0x13,
83 |
84 | ///
85 | /// CAPS LOCK key
86 | ///
87 | CAPITAL = 0x14,
88 |
89 | ///
90 | /// Input Method Editor (IME) Kana mode
91 | ///
92 | KANA = 0x15,
93 |
94 | ///
95 | /// IME Hanguel mode (maintained for compatibility; use HANGUL)
96 | ///
97 | HANGEUL = 0x15,
98 |
99 | ///
100 | /// IME Hangul mode
101 | ///
102 | HANGUL = 0x15,
103 |
104 | // 0x16 : Undefined
105 |
106 | ///
107 | /// IME Junja mode
108 | ///
109 | JUNJA = 0x17,
110 |
111 | ///
112 | /// IME final mode
113 | ///
114 | FINAL = 0x18,
115 |
116 | ///
117 | /// IME Hanja mode
118 | ///
119 | HANJA = 0x19,
120 |
121 | ///
122 | /// IME Kanji mode
123 | ///
124 | KANJI = 0x19,
125 |
126 | // 0x1A : Undefined
127 |
128 | ///
129 | /// ESC key
130 | ///
131 | ESCAPE = 0x1B,
132 |
133 | ///
134 | /// IME convert
135 | ///
136 | CONVERT = 0x1C,
137 |
138 | ///
139 | /// IME nonconvert
140 | ///
141 | NONCONVERT = 0x1D,
142 |
143 | ///
144 | /// IME accept
145 | ///
146 | ACCEPT = 0x1E,
147 |
148 | ///
149 | /// IME mode change request
150 | ///
151 | MODECHANGE = 0x1F,
152 |
153 | ///
154 | /// SPACEBAR
155 | ///
156 | SPACE = 0x20,
157 |
158 | ///
159 | /// PAGE UP key
160 | ///
161 | PRIOR = 0x21,
162 |
163 | ///
164 | /// PAGE DOWN key
165 | ///
166 | NEXT = 0x22,
167 |
168 | ///
169 | /// END key
170 | ///
171 | END = 0x23,
172 |
173 | ///
174 | /// HOME key
175 | ///
176 | HOME = 0x24,
177 |
178 | ///
179 | /// LEFT ARROW key
180 | ///
181 | LEFT = 0x25,
182 |
183 | ///
184 | /// UP ARROW key
185 | ///
186 | UP = 0x26,
187 |
188 | ///
189 | /// RIGHT ARROW key
190 | ///
191 | RIGHT = 0x27,
192 |
193 | ///
194 | /// DOWN ARROW key
195 | ///
196 | DOWN = 0x28,
197 |
198 | ///
199 | /// SELECT key
200 | ///
201 | SELECT = 0x29,
202 |
203 | ///
204 | /// PRINT key
205 | ///
206 | PRINT = 0x2A,
207 |
208 | ///
209 | /// EXECUTE key
210 | ///
211 | EXECUTE = 0x2B,
212 |
213 | ///
214 | /// PRINT SCREEN key
215 | ///
216 | SNAPSHOT = 0x2C,
217 |
218 | ///
219 | /// INS key
220 | ///
221 | INSERT = 0x2D,
222 |
223 | ///
224 | /// DEL key
225 | ///
226 | DELETE = 0x2E,
227 |
228 | ///
229 | /// HELP key
230 | ///
231 | HELP = 0x2F,
232 |
233 | ///
234 | /// 0 key
235 | ///
236 | VK_0 = 0x30,
237 |
238 | ///
239 | /// 1 key
240 | ///
241 | VK_1 = 0x31,
242 |
243 | ///
244 | /// 2 key
245 | ///
246 | VK_2 = 0x32,
247 |
248 | ///
249 | /// 3 key
250 | ///
251 | VK_3 = 0x33,
252 |
253 | ///
254 | /// 4 key
255 | ///
256 | VK_4 = 0x34,
257 |
258 | ///
259 | /// 5 key
260 | ///
261 | VK_5 = 0x35,
262 |
263 | ///
264 | /// 6 key
265 | ///
266 | VK_6 = 0x36,
267 |
268 | ///
269 | /// 7 key
270 | ///
271 | VK_7 = 0x37,
272 |
273 | ///
274 | /// 8 key
275 | ///
276 | VK_8 = 0x38,
277 |
278 | ///
279 | /// 9 key
280 | ///
281 | VK_9 = 0x39,
282 |
283 | //
284 | // 0x3A - 0x40 : Udefined
285 | //
286 |
287 | ///
288 | /// A key
289 | ///
290 | VK_A = 0x41,
291 |
292 | ///
293 | /// B key
294 | ///
295 | VK_B = 0x42,
296 |
297 | ///
298 | /// C key
299 | ///
300 | VK_C = 0x43,
301 |
302 | ///
303 | /// D key
304 | ///
305 | VK_D = 0x44,
306 |
307 | ///
308 | /// E key
309 | ///
310 | VK_E = 0x45,
311 |
312 | ///
313 | /// F key
314 | ///
315 | VK_F = 0x46,
316 |
317 | ///
318 | /// G key
319 | ///
320 | VK_G = 0x47,
321 |
322 | ///
323 | /// H key
324 | ///
325 | VK_H = 0x48,
326 |
327 | ///
328 | /// I key
329 | ///
330 | VK_I = 0x49,
331 |
332 | ///
333 | /// J key
334 | ///
335 | VK_J = 0x4A,
336 |
337 | ///
338 | /// K key
339 | ///
340 | VK_K = 0x4B,
341 |
342 | ///
343 | /// L key
344 | ///
345 | VK_L = 0x4C,
346 |
347 | ///
348 | /// M key
349 | ///
350 | VK_M = 0x4D,
351 |
352 | ///
353 | /// N key
354 | ///
355 | VK_N = 0x4E,
356 |
357 | ///
358 | /// O key
359 | ///
360 | VK_O = 0x4F,
361 |
362 | ///
363 | /// P key
364 | ///
365 | VK_P = 0x50,
366 |
367 | ///
368 | /// Q key
369 | ///
370 | VK_Q = 0x51,
371 |
372 | ///
373 | /// R key
374 | ///
375 | VK_R = 0x52,
376 |
377 | ///
378 | /// S key
379 | ///
380 | VK_S = 0x53,
381 |
382 | ///
383 | /// T key
384 | ///
385 | VK_T = 0x54,
386 |
387 | ///
388 | /// U key
389 | ///
390 | VK_U = 0x55,
391 |
392 | ///
393 | /// V key
394 | ///
395 | VK_V = 0x56,
396 |
397 | ///
398 | /// W key
399 | ///
400 | VK_W = 0x57,
401 |
402 | ///
403 | /// X key
404 | ///
405 | VK_X = 0x58,
406 |
407 | ///
408 | /// Y key
409 | ///
410 | VK_Y = 0x59,
411 |
412 | ///
413 | /// Z key
414 | ///
415 | VK_Z = 0x5A,
416 |
417 | ///
418 | /// Left Windows key (Microsoft Natural keyboard)
419 | ///
420 | LWIN = 0x5B,
421 |
422 | ///
423 | /// Right Windows key (Natural keyboard)
424 | ///
425 | RWIN = 0x5C,
426 |
427 | ///
428 | /// Applications key (Natural keyboard)
429 | ///
430 | APPS = 0x5D,
431 |
432 | // 0x5E : reserved
433 |
434 | ///
435 | /// Computer Sleep key
436 | ///
437 | SLEEP = 0x5F,
438 |
439 | ///
440 | /// Numeric keypad 0 key
441 | ///
442 | NUMPAD0 = 0x60,
443 |
444 | ///
445 | /// Numeric keypad 1 key
446 | ///
447 | NUMPAD1 = 0x61,
448 |
449 | ///
450 | /// Numeric keypad 2 key
451 | ///
452 | NUMPAD2 = 0x62,
453 |
454 | ///
455 | /// Numeric keypad 3 key
456 | ///
457 | NUMPAD3 = 0x63,
458 |
459 | ///
460 | /// Numeric keypad 4 key
461 | ///
462 | NUMPAD4 = 0x64,
463 |
464 | ///
465 | /// Numeric keypad 5 key
466 | ///
467 | NUMPAD5 = 0x65,
468 |
469 | ///
470 | /// Numeric keypad 6 key
471 | ///
472 | NUMPAD6 = 0x66,
473 |
474 | ///
475 | /// Numeric keypad 7 key
476 | ///
477 | NUMPAD7 = 0x67,
478 |
479 | ///
480 | /// Numeric keypad 8 key
481 | ///
482 | NUMPAD8 = 0x68,
483 |
484 | ///
485 | /// Numeric keypad 9 key
486 | ///
487 | NUMPAD9 = 0x69,
488 |
489 | ///
490 | /// Multiply key
491 | ///
492 | MULTIPLY = 0x6A,
493 |
494 | ///
495 | /// Add key
496 | ///
497 | ADD = 0x6B,
498 |
499 | ///
500 | /// Separator key
501 | ///
502 | SEPARATOR = 0x6C,
503 |
504 | ///
505 | /// Subtract key
506 | ///
507 | SUBTRACT = 0x6D,
508 |
509 | ///
510 | /// Decimal key
511 | ///
512 | DECIMAL = 0x6E,
513 |
514 | ///
515 | /// Divide key
516 | ///
517 | DIVIDE = 0x6F,
518 |
519 | ///
520 | /// F1 key
521 | ///
522 | F1 = 0x70,
523 |
524 | ///
525 | /// F2 key
526 | ///
527 | F2 = 0x71,
528 |
529 | ///
530 | /// F3 key
531 | ///
532 | F3 = 0x72,
533 |
534 | ///
535 | /// F4 key
536 | ///
537 | F4 = 0x73,
538 |
539 | ///
540 | /// F5 key
541 | ///
542 | F5 = 0x74,
543 |
544 | ///
545 | /// F6 key
546 | ///
547 | F6 = 0x75,
548 |
549 | ///
550 | /// F7 key
551 | ///
552 | F7 = 0x76,
553 |
554 | ///
555 | /// F8 key
556 | ///
557 | F8 = 0x77,
558 |
559 | ///
560 | /// F9 key
561 | ///
562 | F9 = 0x78,
563 |
564 | ///
565 | /// F10 key
566 | ///
567 | F10 = 0x79,
568 |
569 | ///
570 | /// F11 key
571 | ///
572 | F11 = 0x7A,
573 |
574 | ///
575 | /// F12 key
576 | ///
577 | F12 = 0x7B,
578 |
579 | ///
580 | /// F13 key
581 | ///
582 | F13 = 0x7C,
583 |
584 | ///
585 | /// F14 key
586 | ///
587 | F14 = 0x7D,
588 |
589 | ///
590 | /// F15 key
591 | ///
592 | F15 = 0x7E,
593 |
594 | ///
595 | /// F16 key
596 | ///
597 | F16 = 0x7F,
598 |
599 | ///
600 | /// F17 key
601 | ///
602 | F17 = 0x80,
603 |
604 | ///
605 | /// F18 key
606 | ///
607 | F18 = 0x81,
608 |
609 | ///
610 | /// F19 key
611 | ///
612 | F19 = 0x82,
613 |
614 | ///
615 | /// F20 key
616 | ///
617 | F20 = 0x83,
618 |
619 | ///
620 | /// F21 key
621 | ///
622 | F21 = 0x84,
623 |
624 | ///
625 | /// F22 key
626 | ///
627 | F22 = 0x85,
628 |
629 | ///
630 | /// F23 key
631 | ///
632 | F23 = 0x86,
633 |
634 | ///
635 | /// F24 key
636 | ///
637 | F24 = 0x87,
638 |
639 | //
640 | // 0x88 - 0x8F : Unassigned
641 | //
642 |
643 | ///
644 | /// NUM LOCK key
645 | ///
646 | NUMLOCK = 0x90,
647 |
648 | ///
649 | /// SCROLL LOCK key
650 | ///
651 | SCROLL = 0x91,
652 |
653 | // 0x92 - 0x96 : OEM Specific
654 |
655 | // 0x97 - 0x9F : Unassigned
656 |
657 | //
658 | // L* & R* - left and right Alt, Ctrl and Shift virtual keys.
659 | // Used only as parameters to GetAsyncKeyState() and GetKeyState().
660 | // No other API or message will distinguish left and right keys in this way.
661 | //
662 |
663 | ///
664 | /// Left SHIFT key - Used only as parameters to GetAsyncKeyState() and GetKeyState()
665 | ///
666 | LSHIFT = 0xA0,
667 |
668 | ///
669 | /// Right SHIFT key - Used only as parameters to GetAsyncKeyState() and GetKeyState()
670 | ///
671 | RSHIFT = 0xA1,
672 |
673 | ///
674 | /// Left CONTROL key - Used only as parameters to GetAsyncKeyState() and GetKeyState()
675 | ///
676 | LCONTROL = 0xA2,
677 |
678 | ///
679 | /// Right CONTROL key - Used only as parameters to GetAsyncKeyState() and GetKeyState()
680 | ///
681 | RCONTROL = 0xA3,
682 |
683 | ///
684 | /// Left MENU key - Used only as parameters to GetAsyncKeyState() and GetKeyState()
685 | ///
686 | LMENU = 0xA4,
687 |
688 | ///
689 | /// Right MENU key - Used only as parameters to GetAsyncKeyState() and GetKeyState()
690 | ///
691 | RMENU = 0xA5,
692 |
693 | ///
694 | /// Windows 2000/XP: Browser Back key
695 | ///
696 | BROWSER_BACK = 0xA6,
697 |
698 | ///
699 | /// Windows 2000/XP: Browser Forward key
700 | ///
701 | BROWSER_FORWARD = 0xA7,
702 |
703 | ///
704 | /// Windows 2000/XP: Browser Refresh key
705 | ///
706 | BROWSER_REFRESH = 0xA8,
707 |
708 | ///
709 | /// Windows 2000/XP: Browser Stop key
710 | ///
711 | BROWSER_STOP = 0xA9,
712 |
713 | ///
714 | /// Windows 2000/XP: Browser Search key
715 | ///
716 | BROWSER_SEARCH = 0xAA,
717 |
718 | ///
719 | /// Windows 2000/XP: Browser Favorites key
720 | ///
721 | BROWSER_FAVORITES = 0xAB,
722 |
723 | ///
724 | /// Windows 2000/XP: Browser Start and Home key
725 | ///
726 | BROWSER_HOME = 0xAC,
727 |
728 | ///
729 | /// Windows 2000/XP: Volume Mute key
730 | ///
731 | VOLUME_MUTE = 0xAD,
732 |
733 | ///
734 | /// Windows 2000/XP: Volume Down key
735 | ///
736 | VOLUME_DOWN = 0xAE,
737 |
738 | ///
739 | /// Windows 2000/XP: Volume Up key
740 | ///
741 | VOLUME_UP = 0xAF,
742 |
743 | ///
744 | /// Windows 2000/XP: Next Track key
745 | ///
746 | MEDIA_NEXT_TRACK = 0xB0,
747 |
748 | ///
749 | /// Windows 2000/XP: Previous Track key
750 | ///
751 | MEDIA_PREV_TRACK = 0xB1,
752 |
753 | ///
754 | /// Windows 2000/XP: Stop Media key
755 | ///
756 | MEDIA_STOP = 0xB2,
757 |
758 | ///
759 | /// Windows 2000/XP: Play/Pause Media key
760 | ///
761 | MEDIA_PLAY_PAUSE = 0xB3,
762 |
763 | ///
764 | /// Windows 2000/XP: Start Mail key
765 | ///
766 | LAUNCH_MAIL = 0xB4,
767 |
768 | ///
769 | /// Windows 2000/XP: Select Media key
770 | ///
771 | LAUNCH_MEDIA_SELECT = 0xB5,
772 |
773 | ///
774 | /// Windows 2000/XP: Start Application 1 key
775 | ///
776 | LAUNCH_APP1 = 0xB6,
777 |
778 | ///
779 | /// Windows 2000/XP: Start Application 2 key
780 | ///
781 | LAUNCH_APP2 = 0xB7,
782 |
783 | //
784 | // 0xB8 - 0xB9 : Reserved
785 | //
786 |
787 | ///
788 | /// Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ';:' key
789 | ///
790 | OEM_1 = 0xBA,
791 |
792 | ///
793 | /// Windows 2000/XP: For any country/region, the '+' key
794 | ///
795 | OEM_PLUS = 0xBB,
796 |
797 | ///
798 | /// Windows 2000/XP: For any country/region, the ',' key
799 | ///
800 | OEM_COMMA = 0xBC,
801 |
802 | ///
803 | /// Windows 2000/XP: For any country/region, the '-' key
804 | ///
805 | OEM_MINUS = 0xBD,
806 |
807 | ///
808 | /// Windows 2000/XP: For any country/region, the '.' key
809 | ///
810 | OEM_PERIOD = 0xBE,
811 |
812 | ///
813 | /// Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '/?' key
814 | ///
815 | OEM_2 = 0xBF,
816 |
817 | ///
818 | /// Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '`~' key
819 | ///
820 | OEM_3 = 0xC0,
821 |
822 | //
823 | // 0xC1 - 0xD7 : Reserved
824 | //
825 |
826 | //
827 | // 0xD8 - 0xDA : Unassigned
828 | //
829 |
830 | ///
831 | /// Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '[{' key
832 | ///
833 | OEM_4 = 0xDB,
834 |
835 | ///
836 | /// Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '\|' key
837 | ///
838 | OEM_5 = 0xDC,
839 |
840 | ///
841 | /// Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ']}' key
842 | ///
843 | OEM_6 = 0xDD,
844 |
845 | ///
846 | /// Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the 'single-quote/double-quote' key
847 | ///
848 | OEM_7 = 0xDE,
849 |
850 | ///
851 | /// Used for miscellaneous characters; it can vary by keyboard.
852 | ///
853 | OEM_8 = 0xDF,
854 |
855 | //
856 | // 0xE0 : Reserved
857 | //
858 |
859 | //
860 | // 0xE1 : OEM Specific
861 | //
862 |
863 | ///
864 | /// Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard
865 | ///
866 | OEM_102 = 0xE2,
867 |
868 | //
869 | // (0xE3-E4) : OEM specific
870 | //
871 |
872 | ///
873 | /// Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key
874 | ///
875 | PROCESSKEY = 0xE5,
876 |
877 | //
878 | // 0xE6 : OEM specific
879 | //
880 |
881 | ///
882 | /// Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. The PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP
883 | ///
884 | PACKET = 0xE7,
885 |
886 | //
887 | // 0xE8 : Unassigned
888 | //
889 |
890 | //
891 | // 0xE9-F5 : OEM specific
892 | //
893 |
894 | ///
895 | /// Attn key
896 | ///
897 | ATTN = 0xF6,
898 |
899 | ///
900 | /// CrSel key
901 | ///
902 | CRSEL = 0xF7,
903 |
904 | ///
905 | /// ExSel key
906 | ///
907 | EXSEL = 0xF8,
908 |
909 | ///
910 | /// Erase EOF key
911 | ///
912 | EREOF = 0xF9,
913 |
914 | ///
915 | /// Play key
916 | ///
917 | PLAY = 0xFA,
918 |
919 | ///
920 | /// Zoom key
921 | ///
922 | ZOOM = 0xFB,
923 |
924 | ///
925 | /// Reserved
926 | ///
927 | NONAME = 0xFC,
928 |
929 | ///
930 | /// PA1 key
931 | ///
932 | PA1 = 0xFD,
933 |
934 | ///
935 | /// Clear key
936 | ///
937 | OEM_CLEAR = 0xFE,
938 | }
939 | }
940 |
--------------------------------------------------------------------------------