diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ce6fdd --- /dev/null +++ b/.gitignore @@ -0,0 +1,340 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- Backup*.rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb \ No newline at end of file diff --git a/InputSimulatorPlus/.nuget/NuGet.Config b/InputSimulatorPlus/.nuget/NuGet.Config new file mode 100644 index 0000000..67f8ea0 --- /dev/null +++ b/InputSimulatorPlus/.nuget/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/InputSimulatorPlus/.nuget/NuGet.exe b/InputSimulatorPlus/.nuget/NuGet.exe new file mode 100644 index 0000000..8f61340 Binary files /dev/null and b/InputSimulatorPlus/.nuget/NuGet.exe differ diff --git a/InputSimulatorPlus/.nuget/NuGet.targets b/InputSimulatorPlus/.nuget/NuGet.targets new file mode 100644 index 0000000..2d11ba5 --- /dev/null +++ b/InputSimulatorPlus/.nuget/NuGet.targets @@ -0,0 +1,153 @@ + + + + $(MSBuildProjectDirectory)\..\ + + + false + + + false + + + true + + + false + + + + + + + + + + + $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) + $([System.IO.Path]::Combine($(ProjectDir), "packages.config")) + $([System.IO.Path]::Combine($(SolutionDir), "packages")) + + + + + $(SolutionDir).nuget + packages.config + $(SolutionDir)packages + + + + + $(NuGetToolsPath)\nuget.exe + @(PackageSource) + + "$(NuGetExePath)" + mono --runtime=v4.0.30319 $(NuGetExePath) + + $(TargetDir.Trim('\\')) + + -RequireConsent + + $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(RequireConsentSwitch) -o "$(PackagesDir)" + $(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols + + + + RestorePackages; + $(BuildDependsOn); + + + + + $(BuildDependsOn); + BuildPackage; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/InputSimulatorPlus/BuildProcessTemplates/DefaultTemplate.xaml b/InputSimulatorPlus/BuildProcessTemplates/DefaultTemplate.xaml new file mode 100644 index 0000000..12cc624 --- /dev/null +++ b/InputSimulatorPlus/BuildProcessTemplates/DefaultTemplate.xaml @@ -0,0 +1,602 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Assembly references and imported namespaces serialized as XML namespaces + + + True + + + + + + + + + True + + + + + + + True + + + + + + + + + + + True + + + + + + + + + + + + + + + + + + + + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + + + + + + + + + + + + + + + + + + + True + + + + + + + + + + + + True + + + + + + + + + + + + + + True + + + + + + + + + + + + + + + + + + + True + + + + + + + + + + + + + + + + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + + + + + + + + + + + + + + + + + + + + + + True + + + + + + + + + True + + + + + + + + + + + + + + + True + + + + + + True + + + + + + + + + + + + + + + + + + + + + + + + + True + + + + + + + + + + + + + + + + + + False + + + + + + + + + + True + + + + + + + + + + + + + + + + + + + + + + + + + + True + + + + + + + + + + + + + + + + + + + + + True + + + + + + + + + + + + + + + + + + True + + + + + + + + + + + + + + + True + + + + + + + + + + + + + + + + + + + + + False + + + + + + + + + + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + False + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + + + + + + + + + + + + + + + + + + + + + + + + + False + + + + + + + + + + + + + + + + + + + + + + + + + + False + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/InputSimulatorPlus/BuildProcessTemplates/UpgradeTemplate.xaml b/InputSimulatorPlus/BuildProcessTemplates/UpgradeTemplate.xaml new file mode 100644 index 0000000..166acb2 --- /dev/null +++ b/InputSimulatorPlus/BuildProcessTemplates/UpgradeTemplate.xaml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + [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 }] + + + + [Microsoft.TeamFoundation.Build.Workflow.Activities.ToolPlatform.Auto] + [False] + [False] + + + + + + + + + + [Microsoft.TeamFoundation.VersionControl.Client.RecursionType.OneLevel] + [Microsoft.TeamFoundation.Build.Workflow.BuildVerbosity.Normal] + + + + All + Assembly references and imported namespaces serialized as XML namespaces + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/InputSimulatorPlus/LICENSE.md b/InputSimulatorPlus/LICENSE.md new file mode 100644 index 0000000..425687a --- /dev/null +++ b/InputSimulatorPlus/LICENSE.md @@ -0,0 +1,32 @@ +Ms-PL +Microsoft Public License (Ms-PL) + +This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software. + +1. Definitions + +The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law. + +A "contribution" is the original software, or any additions or changes to the software. + +A "contributor" is any person that distributes its contribution under this license. + +"Licensed patents" are a contributor's patent claims that read directly on its contribution. + +2. Grant of Rights + +(A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create. + +(B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software. + +3. Conditions and Limitations + +(A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. + +(B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically. + +(C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software. + +(D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license. + +(E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement. \ No newline at end of file diff --git a/InputSimulatorPlus/README.md b/InputSimulatorPlus/README.md new file mode 100644 index 0000000..8523dde --- /dev/null +++ b/InputSimulatorPlus/README.md @@ -0,0 +1,78 @@ +# Windows Input Simulator Plus +This library is a fork of Michael Noonan's *Windows Input Simulator* (a C# wrapper around the `SendInput` functionality of Windows) and it can be used as a replacement of the original library without any source code changes. + +This fork supports scan codes, making it compatible with many applications that the original library does not support. + +## NuGet +Install-Package InputSimulatorPlus + +# Examples + +## Example: Single key press +```csharp +public void PressTheSpacebar() +{ + InputSimulator.SimulateKeyPress(VirtualKeyCode.SPACE); +} +``` + +## Example: Key-down and Key-up +```csharp +public void ShoutHello() +{ + // Simulate each key stroke + InputSimulator.SimulateKeyDown(VirtualKeyCode.SHIFT); + InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_H); + InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_E); + InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_L); + InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_L); + InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_O); + InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_1); + InputSimulator.SimulateKeyUp(VirtualKeyCode.SHIFT); + + // Alternatively you can simulate text entry to acheive the same end result + InputSimulator.SimulateTextEntry("HELLO!"); +} +``` + +## Example: Modified keystrokes such as CTRL-C +```csharp +public void SimulateSomeModifiedKeystrokes() +{ + // CTRL-C (effectively a copy command in many situations) + InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_C); + + // You can simulate chords with multiple modifiers + // For example CTRL-K-C whic is simulated as + // CTRL-down, K, C, CTRL-up + InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, new [] {VirtualKeyCode.VK_K, VirtualKeyCode.VK_C}); + + // You can simulate complex chords with multiple modifiers and key presses + // For example CTRL-ALT-SHIFT-ESC-K which is simulated as + // CTRL-down, ALT-down, SHIFT-down, press ESC, press K, SHIFT-up, ALT-up, CTRL-up + InputSimulator.SimulateModifiedKeyStroke( + new[] { VirtualKeyCode.CONTROL, VirtualKeyCode.MENU, VirtualKeyCode.SHIFT }, + new[] { VirtualKeyCode.ESCAPE, VirtualKeyCode.VK_K }); +} +``` + +## Example: Simulate text entry +```csharp +public void SayHello() +{ + InputSimulator.SimulateTextEntry("Say hello!"); +} +``` + +## Example: Determine the state of different types of keys +```csharp +public void GetKeyStatus() +{ + // Determines if the shift key is currently down + var isShiftKeyDown = InputSimulator.IsKeyDown(VirtualKeyCode.SHIFT); + + // Determines if the caps lock key is currently in effect (toggled on) + var isCapsLockOn = InputSimulator.IsTogglingKeyInEffect(VirtualKeyCode.CAPITAL); +} +``` + diff --git a/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/App.xaml b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/App.xaml new file mode 100644 index 0000000..7146b2e --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/App.xaml @@ -0,0 +1,8 @@ + + + + + diff --git a/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/App.xaml.cs b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/App.xaml.cs new file mode 100644 index 0000000..fc9f846 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/App.xaml.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Windows; + +namespace InputSimulator.SampleClient.Wpf +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/MainWindow.xaml b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/MainWindow.xaml new file mode 100644 index 0000000..cb15ab6 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/MainWindow.xaml @@ -0,0 +1,8 @@ + + + + + diff --git a/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/MainWindow.xaml.cs b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/MainWindow.xaml.cs new file mode 100644 index 0000000..1083ae3 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/MainWindow.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace InputSimulator.SampleClient.Wpf +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/Properties/AssemblyInfo.cs b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..5a98214 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("InputSimulator.SampleClient.Wpf")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("InputSimulator.SampleClient.Wpf")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/Properties/Resources.Designer.cs b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/Properties/Resources.Designer.cs new file mode 100644 index 0000000..e5f3c11 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30128.1 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace InputSimulator.SampleClient.Wpf.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("InputSimulator.SampleClient.Wpf.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/Properties/Resources.resx b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/Properties/Settings.Designer.cs b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/Properties/Settings.Designer.cs new file mode 100644 index 0000000..66b865d --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30128.1 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace InputSimulator.SampleClient.Wpf.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/Properties/Settings.settings b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/Properties/Settings.settings new file mode 100644 index 0000000..033d7a5 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/WindowsInput.SampleClient.Wpf.csproj b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/WindowsInput.SampleClient.Wpf.csproj new file mode 100644 index 0000000..9d55488 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.SampleClient.Wpf/WindowsInput.SampleClient.Wpf.csproj @@ -0,0 +1,109 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {DE70B414-25CB-4C64-82EE-3955FECDF762} + WinExe + Properties + InputSimulator.SampleClient.Wpf + InputSimulator.SampleClient.Wpf + v4.0 + Client + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + {3549CD6F-80F8-450F-B99E-CF0A736B1F2A} + InputSimulator + + + + + \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput.Tests/InputBuilderTests.cs b/InputSimulatorPlus/WindowsInput.Tests/InputBuilderTests.cs new file mode 100644 index 0000000..8c51ffc --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.Tests/InputBuilderTests.cs @@ -0,0 +1,21 @@ +using System.Linq; +using NUnit.Framework; +using WindowsInput.Native; + +namespace WindowsInput.Tests +{ + [TestFixture] + public class InputBuilderTests + { + [Test] + public void AddKeyDown() + { + var builder = new InputBuilder(); + Assert.That(builder.ToArray(), Is.Empty); + builder.AddKeyDown(VirtualKeyCode.VK_A); + Assert.That(builder.Count(), Is.EqualTo(1)); + Assert.That(builder[0].Type, Is.EqualTo((uint)InputType.Keyboard)); + Assert.That(builder[0].Data.Keyboard.KeyCode, Is.EqualTo((ushort)VirtualKeyCode.VK_A)); + } + } +} diff --git a/InputSimulatorPlus/WindowsInput.Tests/InputSimulatorExamples.cs b/InputSimulatorPlus/WindowsInput.Tests/InputSimulatorExamples.cs new file mode 100644 index 0000000..c4cf317 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.Tests/InputSimulatorExamples.cs @@ -0,0 +1,82 @@ +using NUnit.Framework; +using WindowsInput.Native; + +namespace WindowsInput.Tests +{ + [TestFixture] + public class InputSimulatorExamples + { + [Test] + [Explicit] + public void OpenWindowsExplorer() + { + var sim = new InputSimulator(); + sim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.VK_E); + } + + [Test] + [Explicit] + public void SayHello() + { + var sim = new InputSimulator(); + sim.Keyboard + .ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.VK_R) + .Sleep(1000) + .TextEntry("notepad") + .Sleep(1000) + .KeyPress(VirtualKeyCode.RETURN) + .Sleep(1000) + .TextEntry("These are your orders if you choose to accept them...") + .TextEntry("This message will self destruct in 5 seconds.") + .Sleep(5000) + .ModifiedKeyStroke(VirtualKeyCode.MENU, VirtualKeyCode.SPACE) + .KeyPress(VirtualKeyCode.DOWN) + .KeyPress(VirtualKeyCode.RETURN); + + var i = 10; + while (i-- > 0) + { + sim.Keyboard.KeyPress(VirtualKeyCode.DOWN).Sleep(100); + } + + sim.Keyboard + .KeyPress(VirtualKeyCode.RETURN) + .Sleep(1000) + .ModifiedKeyStroke(VirtualKeyCode.MENU, VirtualKeyCode.F4) + .KeyPress(VirtualKeyCode.VK_N); + } + + [Test] + [Explicit] + public void AnotherTest() + { + var sim = new InputSimulator(); + sim.Keyboard.KeyPress(VirtualKeyCode.SPACE); + + sim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.VK_R) + .Sleep(1000) + .TextEntry("mspaint") + .Sleep(1000) + .KeyPress(VirtualKeyCode.RETURN) + .Sleep(1000) + .Mouse + .LeftButtonDown() + .MoveMouseToPositionOnVirtualDesktop(65535/2, 65535/2) + .LeftButtonUp(); + + } + + [Test] + [Explicit] + public void TestMouseMoveTo() + { + var sim = new InputSimulator(); + sim.Mouse + .MoveMouseTo(0, 0) + .Sleep(1000) + .MoveMouseTo(65535, 65535) + .Sleep(1000) + .MoveMouseTo(65535/2, 65535/2); + } + } +} \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput.Tests/Properties/AssemblyInfo.cs b/InputSimulatorPlus/WindowsInput.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..749ab1e --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("WindowsInput.UnitTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("WindowsInput.UnitTests")] +[assembly: AssemblyCopyright("Copyright © michaelnoonan 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("9e1ff335-ed74-4135-92cf-5e4cf1d38344")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("0.2.0.0")] +[assembly: AssemblyFileVersion("0.2.0.0")] diff --git a/InputSimulatorPlus/WindowsInput.Tests/UnicodeText/UnicodeRange.cs b/InputSimulatorPlus/WindowsInput.Tests/UnicodeText/UnicodeRange.cs new file mode 100644 index 0000000..3522fee --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.Tests/UnicodeText/UnicodeRange.cs @@ -0,0 +1,33 @@ +using System.Text; + +namespace WindowsInput.Tests.UnicodeText +{ + public class UnicodeRange + { + public string Name { get; set; } + public int Low { get; set; } + public int High { get; set; } + + public string Characters + { + get + { + var i = Low; + var sb = new StringBuilder(High - Low + 10); + while (i <= High) + { + sb.Append(char.ConvertFromUtf32(i)); + i++; + } + return sb.ToString(); + } + } + + public UnicodeRange(string name, int low, int high) + { + Name = name; + Low = low; + High = high; + } + } +} \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput.Tests/UnicodeText/UnicodeTestForm.Designer.cs b/InputSimulatorPlus/WindowsInput.Tests/UnicodeText/UnicodeTestForm.Designer.cs new file mode 100644 index 0000000..6d5dca4 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.Tests/UnicodeText/UnicodeTestForm.Designer.cs @@ -0,0 +1,76 @@ +namespace WindowsInput.Tests.UnicodeText +{ + partial class UnicodeTestForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.RecievedTextBox = new System.Windows.Forms.TextBox(); + this.ExpectedTextBox = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // RecievedTextBox + // + this.RecievedTextBox.Dock = System.Windows.Forms.DockStyle.Top; + this.RecievedTextBox.Font = new System.Drawing.Font("Segoe UI", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.RecievedTextBox.Location = new System.Drawing.Point(0, 0); + this.RecievedTextBox.Name = "RecievedTextBox"; + this.RecievedTextBox.Size = new System.Drawing.Size(981, 39); + this.RecievedTextBox.TabIndex = 0; + // + // ExpectedTextBox + // + this.ExpectedTextBox.Dock = System.Windows.Forms.DockStyle.Bottom; + this.ExpectedTextBox.Font = new System.Drawing.Font("Segoe UI", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.ExpectedTextBox.Location = new System.Drawing.Point(0, 40); + this.ExpectedTextBox.Name = "ExpectedTextBox"; + this.ExpectedTextBox.ReadOnly = true; + this.ExpectedTextBox.Size = new System.Drawing.Size(981, 39); + this.ExpectedTextBox.TabIndex = 1; + // + // UnicodeTestForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(981, 79); + this.Controls.Add(this.ExpectedTextBox); + this.Controls.Add(this.RecievedTextBox); + this.Name = "UnicodeTestForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "UnicodeTestForm"; + this.TopMost = true; + this.WindowState = System.Windows.Forms.FormWindowState.Maximized; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox RecievedTextBox; + private System.Windows.Forms.TextBox ExpectedTextBox; + } +} \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput.Tests/UnicodeText/UnicodeTestForm.cs b/InputSimulatorPlus/WindowsInput.Tests/UnicodeText/UnicodeTestForm.cs new file mode 100644 index 0000000..4bdab90 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.Tests/UnicodeText/UnicodeTestForm.cs @@ -0,0 +1,27 @@ +using System; +using System.Windows.Forms; + +namespace WindowsInput.Tests.UnicodeText +{ + public partial class UnicodeTestForm : Form + { + public UnicodeTestForm() + { + InitializeComponent(); + } + + public string Expected + { + get { return ExpectedTextBox.Text; } + set { ExpectedTextBox.Text = value; } + } + + public string Recieved { get { return RecievedTextBox.Text; } } + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + RecievedTextBox.Focus(); + } + } +} diff --git a/InputSimulatorPlus/WindowsInput.Tests/UnicodeText/UnicodeTestForm.resx b/InputSimulatorPlus/WindowsInput.Tests/UnicodeText/UnicodeTestForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.Tests/UnicodeText/UnicodeTestForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput.Tests/UnicodeText/UnicodeTextTests.cs b/InputSimulatorPlus/WindowsInput.Tests/UnicodeText/UnicodeTextTests.cs new file mode 100644 index 0000000..4373dcb --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.Tests/UnicodeText/UnicodeTextTests.cs @@ -0,0 +1,223 @@ +using System; +using System.Net; +using System.Threading; +using System.Threading.Tasks; +using HtmlAgilityPack; +using NUnit.Framework; + +namespace WindowsInput.Tests.UnicodeText +{ + [TestFixture] + public class UnicodeTextTests + { + private TestCaseData[] _unicodeTestCases; + public TestCaseData[] UnicodeTestCases + { + get + { + if (_unicodeTestCases == null) + { + var ranges = GetUnicodeRanges(); + _unicodeTestCases = Array.ConvertAll(ranges, BuildTestCase); + } + return _unicodeTestCases; + } + } + + private TestCaseData BuildTestCase(UnicodeRange input) + { + return new TestCaseData(input).SetName(input.Name); + } + + [Test] + [Explicit] + [TestCaseSource("UnicodeTestCases")] + public void TestUnicodeRanges(UnicodeRange range) + { + // ReSharper disable AccessToDisposedClosure + using (var form = new UnicodeTestForm + { + Expected = range.Characters + }) + { + var ready = false; + var formTask = Task.Factory.StartNew( + () => + { + form.Shown += (x, y) => ready = true; + form.ShowDialog(); + }, TaskCreationOptions.LongRunning); + + var simTask = Task.Factory.StartNew( + () => + { + while (!ready) + { + Thread.Sleep(250); + } + var sim = new InputSimulator(); + sim.Keyboard.TextEntry(range.Characters); + while (form.Recieved != form.Expected) + { + Thread.Sleep(500); + } + form.Close(); + }, TaskCreationOptions.LongRunning); + + Task.WaitAll(new[] {formTask, simTask}, TimeSpan.FromSeconds(60)); + Assert.That(form.Recieved, Is.EqualTo(form.Expected)); + } + // ReSharper restore AccessToDisposedClosure + } + + [Test] + [Explicit] + public void GetCharacterRanges() + { + using (var client = new WebClient()) + { + var html = client.DownloadString("http://jrgraphix.net/r/Unicode/"); + var htmlDoc = new HtmlDocument(); + htmlDoc.LoadHtml(html); + foreach (var link in htmlDoc.DocumentNode.SelectNodes("//a[@href]")) + { + var a = link.GetAttributeValue("href", "unknown"); + if (a.Contains("Unicode")) + { + a = "0x" + a.Replace("/r/Unicode/", "").Replace("-", ", 0x") + "),"; + Console.WriteLine("new UnicodeRange(\"" + link.InnerText + "\", " + a); + } + } + } + } + + public UnicodeRange[] GetUnicodeRanges() + { + return new[] + { + new UnicodeRange("Basic Latin", 0x0020, 0x007F), + new UnicodeRange("Block Elements", 0x2580, 0x259F), + new UnicodeRange("Latin-1 Supplement", 0x00A0, 0x00FF), + new UnicodeRange("Geometric Shapes", 0x25A0, 0x25FF), + new UnicodeRange("Latin Extended-A", 0x0100, 0x017F), + new UnicodeRange("Miscellaneous Symbols", 0x2600, 0x26FF), + new UnicodeRange("Latin Extended-B", 0x0180, 0x024F), + new UnicodeRange("Dingbats", 0x2700, 0x27BF), + new UnicodeRange("IPA Extensions", 0x0250, 0x02AF), + new UnicodeRange("Miscellaneous Mathematical Symbols-A", 0x27C0, 0x27EF), + new UnicodeRange("Spacing Modifier Letters", 0x02B0, 0x02FF), + new UnicodeRange("Supplemental Arrows-A", 0x27F0, 0x27FF), + new UnicodeRange("Combining Diacritical Marks", 0x0300, 0x036F), + new UnicodeRange("Braille Patterns", 0x2800, 0x28FF), + new UnicodeRange("Greek and Coptic", 0x0370, 0x03FF), + new UnicodeRange("Supplemental Arrows-B", 0x2900, 0x297F), + new UnicodeRange("Cyrillic", 0x0400, 0x04FF), + new UnicodeRange("Miscellaneous Mathematical Symbols-B", 0x2980, 0x29FF), + new UnicodeRange("Cyrillic Supplementary", 0x0500, 0x052F), + new UnicodeRange("Supplemental Mathematical Operators", 0x2A00, 0x2AFF), + new UnicodeRange("Armenian", 0x0530, 0x058F), + new UnicodeRange("Miscellaneous Symbols and Arrows", 0x2B00, 0x2BFF), + new UnicodeRange("Hebrew", 0x0590, 0x05FF), + new UnicodeRange("CJK Radicals Supplement", 0x2E80, 0x2EFF), + new UnicodeRange("Arabic", 0x0600, 0x06FF), + new UnicodeRange("Kangxi Radicals", 0x2F00, 0x2FDF), + new UnicodeRange("Syriac", 0x0700, 0x074F), + new UnicodeRange("Ideographic Description Characters", 0x2FF0, 0x2FFF), + new UnicodeRange("Thaana", 0x0780, 0x07BF), + new UnicodeRange("CJK Symbols and Punctuation", 0x3000, 0x303F), + new UnicodeRange("Devanagari", 0x0900, 0x097F), + new UnicodeRange("Hiragana", 0x3040, 0x309F), + new UnicodeRange("Bengali", 0x0980, 0x09FF), + new UnicodeRange("Katakana", 0x30A0, 0x30FF), + new UnicodeRange("Gurmukhi", 0x0A00, 0x0A7F), + new UnicodeRange("Bopomofo", 0x3100, 0x312F), + new UnicodeRange("Gujarati", 0x0A80, 0x0AFF), + new UnicodeRange("Hangul Compatibility Jamo", 0x3130, 0x318F), + new UnicodeRange("Oriya", 0x0B00, 0x0B7F), + new UnicodeRange("Kanbun", 0x3190, 0x319F), + new UnicodeRange("Tamil", 0x0B80, 0x0BFF), + new UnicodeRange("Bopomofo Extended", 0x31A0, 0x31BF), + new UnicodeRange("Telugu", 0x0C00, 0x0C7F), + new UnicodeRange("Katakana Phonetic Extensions", 0x31F0, 0x31FF), + new UnicodeRange("Kannada", 0x0C80, 0x0CFF), + new UnicodeRange("Enclosed CJK Letters and Months", 0x3200, 0x32FF), + new UnicodeRange("Malayalam", 0x0D00, 0x0D7F), + new UnicodeRange("CJK Compatibility", 0x3300, 0x33FF), + new UnicodeRange("Sinhala", 0x0D80, 0x0DFF), + new UnicodeRange("CJK Unified Ideographs Extension A", 0x3400, 0x4DBF), + new UnicodeRange("Thai", 0x0E00, 0x0E7F), + new UnicodeRange("Yijing Hexagram Symbols", 0x4DC0, 0x4DFF), + new UnicodeRange("Lao", 0x0E80, 0x0EFF), + new UnicodeRange("CJK Unified Ideographs", 0x4E00, 0x9FFF), + new UnicodeRange("Tibetan", 0x0F00, 0x0FFF), + new UnicodeRange("Yi Syllables", 0xA000, 0xA48F), + new UnicodeRange("Myanmar", 0x1000, 0x109F), + new UnicodeRange("Yi Radicals", 0xA490, 0xA4CF), + new UnicodeRange("Georgian", 0x10A0, 0x10FF), + new UnicodeRange("Hangul Syllables", 0xAC00, 0xD7AF), + new UnicodeRange("Hangul Jamo", 0x1100, 0x11FF), + new UnicodeRange("High Surrogates", 0xD800, 0xDB7F), + new UnicodeRange("Ethiopic", 0x1200, 0x137F), + new UnicodeRange("High Private Use Surrogates", 0xDB80, 0xDBFF), + new UnicodeRange("Cherokee", 0x13A0, 0x13FF), + new UnicodeRange("Low Surrogates", 0xDC00, 0xDFFF), + new UnicodeRange("Unified Canadian Aboriginal Syllabics", 0x1400, 0x167F), + new UnicodeRange("Private Use Area", 0xE000, 0xF8FF), + new UnicodeRange("Ogham", 0x1680, 0x169F), + new UnicodeRange("CJK Compatibility Ideographs", 0xF900, 0xFAFF), + new UnicodeRange("Runic", 0x16A0, 0x16FF), + new UnicodeRange("Alphabetic Presentation Forms", 0xFB00, 0xFB4F), + new UnicodeRange("Tagalog", 0x1700, 0x171F), + new UnicodeRange("Arabic Presentation Forms-A", 0xFB50, 0xFDFF), + new UnicodeRange("Hanunoo", 0x1720, 0x173F), + new UnicodeRange("Variation Selectors", 0xFE00, 0xFE0F), + new UnicodeRange("Buhid", 0x1740, 0x175F), + new UnicodeRange("Combining Half Marks", 0xFE20, 0xFE2F), + new UnicodeRange("Tagbanwa", 0x1760, 0x177F), + new UnicodeRange("CJK Compatibility Forms", 0xFE30, 0xFE4F), + new UnicodeRange("Khmer", 0x1780, 0x17FF), + new UnicodeRange("Small Form Variants", 0xFE50, 0xFE6F), + new UnicodeRange("Mongolian", 0x1800, 0x18AF), + new UnicodeRange("Arabic Presentation Forms-B", 0xFE70, 0xFEFF), + new UnicodeRange("Limbu", 0x1900, 0x194F), + new UnicodeRange("Halfwidth and Fullwidth Forms", 0xFF00, 0xFFEF), + new UnicodeRange("Tai Le", 0x1950, 0x197F), + new UnicodeRange("Specials", 0xFFF0, 0xFFFF), + new UnicodeRange("Khmer Symbols", 0x19E0, 0x19FF), + new UnicodeRange("Linear B Syllabary", 0x10000, 0x1007F), + new UnicodeRange("Phonetic Extensions", 0x1D00, 0x1D7F), + new UnicodeRange("Linear B Ideograms", 0x10080, 0x100FF), + new UnicodeRange("Latin Extended Additional", 0x1E00, 0x1EFF), + new UnicodeRange("Aegean Numbers", 0x10100, 0x1013F), + new UnicodeRange("Greek Extended", 0x1F00, 0x1FFF), + new UnicodeRange("Old Italic", 0x10300, 0x1032F), + new UnicodeRange("General Punctuation", 0x2000, 0x206F), + new UnicodeRange("Gothic", 0x10330, 0x1034F), + new UnicodeRange("Superscripts and Subscripts", 0x2070, 0x209F), + new UnicodeRange("Ugaritic", 0x10380, 0x1039F), + new UnicodeRange("Currency Symbols", 0x20A0, 0x20CF), + new UnicodeRange("Deseret", 0x10400, 0x1044F), + new UnicodeRange("Combining Diacritical Marks for Symbols", 0x20D0, 0x20FF), + new UnicodeRange("Shavian", 0x10450, 0x1047F), + new UnicodeRange("Letterlike Symbols", 0x2100, 0x214F), + new UnicodeRange("Osmanya", 0x10480, 0x104AF), + new UnicodeRange("Number Forms", 0x2150, 0x218F), + new UnicodeRange("Cypriot Syllabary", 0x10800, 0x1083F), + new UnicodeRange("Arrows", 0x2190, 0x21FF), + new UnicodeRange("Byzantine Musical Symbols", 0x1D000, 0x1D0FF), + new UnicodeRange("Mathematical Operators", 0x2200, 0x22FF), + new UnicodeRange("Musical Symbols", 0x1D100, 0x1D1FF), + new UnicodeRange("Miscellaneous Technical", 0x2300, 0x23FF), + new UnicodeRange("Tai Xuan Jing Symbols", 0x1D300, 0x1D35F), + new UnicodeRange("Control Pictures", 0x2400, 0x243F), + new UnicodeRange("Mathematical Alphanumeric Symbols", 0x1D400, 0x1D7FF), + new UnicodeRange("Optical Character Recognition", 0x2440, 0x245F), + new UnicodeRange("CJK Unified Ideographs Extension B", 0x20000, 0x2A6DF), + new UnicodeRange("Enclosed Alphanumerics", 0x2460, 0x24FF), + new UnicodeRange("CJK Compatibility Ideographs Supplement", 0x2F800, 0x2FA1F), + new UnicodeRange("Box Drawing", 0x2500, 0x257F), + new UnicodeRange("Tags", 0xE0000, 0xE007F) + }; + } + } +} \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput.Tests/WindowsInput.Tests.csproj b/InputSimulatorPlus/WindowsInput.Tests/WindowsInput.Tests.csproj new file mode 100644 index 0000000..704a44d --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.Tests/WindowsInput.Tests.csproj @@ -0,0 +1,100 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {93982D2F-BEAD-49F7-86A9-C68159410F28} + Library + Properties + WindowsInput.Tests + WindowsInput.Tests + v4.5 + 512 + + ..\ + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + true + + + WindowsInput.snk + + + + ..\packages\HtmlAgilityPack.1.4.6\lib\Net45\HtmlAgilityPack.dll + + + ..\packages\NUnit.2.6.2\lib\nunit.framework.dll + + + + + + + + + + + + + + + + + Form + + + UnicodeTestForm.cs + + + + + + + + + + UnicodeTestForm.cs + + + + + + + + {3549cd6f-80f8-450f-b99e-cf0a736b1f2a} + WindowsInput + + + + + + \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput.Tests/WindowsInput.snk b/InputSimulatorPlus/WindowsInput.Tests/WindowsInput.snk new file mode 100644 index 0000000..5104dcc Binary files /dev/null and b/InputSimulatorPlus/WindowsInput.Tests/WindowsInput.snk differ diff --git a/InputSimulatorPlus/WindowsInput.Tests/packages.config b/InputSimulatorPlus/WindowsInput.Tests/packages.config new file mode 100644 index 0000000..0f5e6b7 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.Tests/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput.sln b/InputSimulatorPlus/WindowsInput.sln new file mode 100644 index 0000000..abf735d --- /dev/null +++ b/InputSimulatorPlus/WindowsInput.sln @@ -0,0 +1,33 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.27004.2006 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsInput", "WindowsInput\WindowsInput.csproj", "{3549CD6F-80F8-450F-B99E-CF0A736B1F2A}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{C2945350-728A-4D62-93D6-FA5F5015A7C6}" + ProjectSection(SolutionItems) = preProject + .nuget\NuGet.Config = .nuget\NuGet.Config + .nuget\NuGet.exe = .nuget\NuGet.exe + .nuget\NuGet.targets = .nuget\NuGet.targets + .nuget\package.nuspec = .nuget\package.nuspec + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3549CD6F-80F8-450F-B99E-CF0A736B1F2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3549CD6F-80F8-450F-B99E-CF0A736B1F2A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3549CD6F-80F8-450F-B99E-CF0A736B1F2A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3549CD6F-80F8-450F-B99E-CF0A736B1F2A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4CF19F51-46F7-4DE1-9BC3-2EEC71EE691A} + EndGlobalSection +EndGlobal diff --git a/InputSimulatorPlus/WindowsInput/IInputDeviceStateAdaptor.cs b/InputSimulatorPlus/WindowsInput/IInputDeviceStateAdaptor.cs new file mode 100644 index 0000000..5512357 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/IInputDeviceStateAdaptor.cs @@ -0,0 +1,55 @@ +using WindowsInput.Native; + +namespace WindowsInput +{ + /// + /// The contract for a service that interprets the state of input devices. + /// + public interface IInputDeviceStateAdaptor + { + /// + /// Determines whether the specified key is up or down. + /// + /// The for the key. + /// + /// true if the key is down; otherwise, false. + /// + bool IsKeyDown(VirtualKeyCode keyCode); + + /// + /// Determines whether the specified key is up or down. + /// + /// The for the key. + /// + /// true if the key is up; otherwise, false. + /// + bool IsKeyUp(VirtualKeyCode keyCode); + + /// + /// 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. + /// + /// The for the key. + /// + /// true if the key is down; otherwise, false. + /// + bool IsHardwareKeyDown(VirtualKeyCode keyCode); + + /// + /// 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. + /// + /// The for the key. + /// + /// true if the key is up; otherwise, false. + /// + bool IsHardwareKeyUp(VirtualKeyCode keyCode); + + /// + /// Determines whether the toggling key is toggled on (in-effect) or not. + /// + /// The for the key. + /// + /// true if the toggling key is toggled on (in-effect); otherwise, false. + /// + bool IsTogglingKeyInEffect(VirtualKeyCode keyCode); + } +} \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput/IInputMessageDispatcher.cs b/InputSimulatorPlus/WindowsInput/IInputMessageDispatcher.cs new file mode 100644 index 0000000..e8db959 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/IInputMessageDispatcher.cs @@ -0,0 +1,20 @@ +using System; +using WindowsInput.Native; + +namespace WindowsInput +{ + /// + /// The contract for a service that dispatches messages to the appropriate destination. + /// + internal interface IInputMessageDispatcher + { + /// + /// Dispatches the specified list of messages in their specified order. + /// + /// The list of messages to be dispatched. + /// If the array is empty. + /// If the array is null. + /// If the any of the commands in the array could not be sent successfully. + void DispatchInput(INPUT[] inputs); + } +} diff --git a/InputSimulatorPlus/WindowsInput/IInputSimulator.cs b/InputSimulatorPlus/WindowsInput/IInputSimulator.cs new file mode 100644 index 0000000..e8540a2 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/IInputSimulator.cs @@ -0,0 +1,26 @@ +namespace WindowsInput +{ + /// + /// The contract for a service that simulates Keyboard and Mouse input and Hardware Input Device state detection for the Windows Platform. + /// + public interface IInputSimulator + { + /// + /// Gets the instance for simulating Keyboard input. + /// + /// The instance. + IKeyboardSimulator Keyboard { get; } + + /// + /// Gets the instance for simulating Mouse input. + /// + /// The instance. + IMouseSimulator Mouse { get; } + + /// + /// Gets the instance for determining the state of the various input devices. + /// + /// The instance. + IInputDeviceStateAdaptor InputDeviceState { get; } + } +} \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput/IKeyboardSimulator.cs b/InputSimulatorPlus/WindowsInput/IKeyboardSimulator.cs new file mode 100644 index 0000000..a8a2e00 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/IKeyboardSimulator.cs @@ -0,0 +1,208 @@ +using System; +using System.Collections.Generic; +using WindowsInput.Native; + +namespace WindowsInput +{ + /// + /// The service contract for a keyboard simulator for the Windows platform. + /// + public interface IKeyboardSimulator + { + /// + /// Gets the instance for simulating Mouse input. + /// + /// The instance. + IMouseSimulator Mouse { get; } + + /// + /// Simulates the key down gesture for the specified key. + /// + /// The for the key. + IKeyboardSimulator KeyDown(VirtualKeyCode keyCode); + + /// + /// Simulates the key press gesture for the specified key. + /// + /// The for the key. + IKeyboardSimulator KeyPress(VirtualKeyCode keyCode); + + /// + /// Simulates a key press for each of the specified key codes in the order they are specified. + /// + /// + IKeyboardSimulator KeyPress(params VirtualKeyCode[] keyCodes); + + /// + /// Simulates the key up gesture for the specified key. + /// + /// The for the key. + IKeyboardSimulator KeyUp(VirtualKeyCode keyCode); + + /// + /// 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. + /// The flow is Modifiers KeyDown in order, Keys Press in order, Modifiers KeyUp in reverse order. + /// + /// The list of s for the modifier keys. + /// The list of s for the keys to simulate. + IKeyboardSimulator ModifiedKeyStroke(IEnumerable modifierKeyCodes, IEnumerable keyCodes); + + /// + /// Manually creates a keystroke and delays the keyup by a specified number of ms. + /// The flow is Modifiers KeyDown in order, Keys Press in order, Modifiers KeyUp in reverse order. + /// + /// The list of s for the modifier keys. + /// The list of s for the keys to simulate. + /// Delay in ms between keydown and keyup of final keyCode. + IKeyboardSimulator DelayedModifiedKeyStroke(IEnumerable modifierKeyCodes, IEnumerable keyCodes, int delay); + + /// + /// 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. + /// The flow is Modifiers KeyDown in order, Key Press, Modifiers KeyUp in reverse order. + /// + /// The list of s for the modifier keys. + /// The for the key. + IKeyboardSimulator ModifiedKeyStroke(IEnumerable modifierKeyCodes, VirtualKeyCode keyCode); + + /// + /// 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. + /// The flow is Modifier KeyDown, Keys Press in order, Modifier KeyUp. + /// + /// The for the modifier key. + /// The list of s for the keys to simulate. + IKeyboardSimulator ModifiedKeyStroke(VirtualKeyCode modifierKey, IEnumerable keyCodes); + + /// + /// Simulates a simple modified keystroke like CTRL-C where CTRL is the modifierKey and C is the key. + /// The flow is Modifier KeyDown, Key Press, Modifier KeyUp. + /// + /// The for the modifier key. + /// The for the key. + IKeyboardSimulator ModifiedKeyStroke(VirtualKeyCode modifierKeyCode, VirtualKeyCode keyCode); + + /// + /// Calls the Win32 SendInput method to simulate a KeyDown. + /// + /// The to press + IKeyboardSimulator KeyDown(DirectInputKeyCode dikCode); + + /// + /// Calls the Win32 SendInput method to simulate a KeyUp. + /// + /// The to lift up + IKeyboardSimulator KeyUp(DirectInputKeyCode dikCode); + + /// + /// Calls the Win32 SendInput method with a KeyDown and KeyUp message in the same input sequence in order to simulate a Key PRESS. + /// + /// The to press + IKeyboardSimulator KeyPress(DirectInputKeyCode dikCode); + + /// + /// Calls the Win32 SendInput method with a KeyDown and KeyUp message in the same input sequence in order to simulate a Key PRESS. + /// + /// The to press + /// Delay in ms between keydown and keyup of final keyCode. + IKeyboardSimulator DelayedKeyPress(DirectInputKeyCode dikCode, int delay); + + + /// + /// Calls the Win32 SendInput method with a KeyUp message + /// + /// The to press + /// Delay in ms between keydown and keyup of final keyCode. + IKeyboardSimulator DelayedKeyPressUp(DirectInputKeyCode dikCode, int delay); + + /// + /// Calls the Win32 SendInput method with a KeyDown message + /// + /// The to press + /// Delay in ms between keydown and keyup of final keyCode. + IKeyboardSimulator DelayedKeyPressDown(DirectInputKeyCode dikCode, int delay); + + + /// + /// Simulates a simple modified keystroke like CTRL-C where CTRL is the modifierKey and C is the key. + /// The flow is Modifier KeyDown, Key Press, Modifier KeyUp. + /// + /// The modifier key + /// The key to simulate + IKeyboardSimulator ModifiedKeyStroke(DirectInputKeyCode modifierDikCode, DirectInputKeyCode dikCode); + + /// + /// 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. + /// The flow is Modifiers KeyDown in order, Key Press, Modifiers KeyUp in reverse order. + /// + /// The list of modifier keys + /// The key to simulate + IKeyboardSimulator ModifiedKeyStroke(IEnumerable modifierDikCodes, DirectInputKeyCode dikCode); + + /// + /// 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. + /// The flow is Modifiers KeyDown in order, Key Press, Modifiers KeyUp in reverse order. + /// + /// The list of modifier keys + /// The key to simulate + /// Delay in ms between keydown and keyup of final keyCode. + IKeyboardSimulator DelayedModifiedKeyStroke(IEnumerable modifierDikCodes, DirectInputKeyCode dikCode, int delay); + + /// + /// 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. + /// The flow is Modifiers KeyDown in order, Key Press + /// + /// The list of modifier keys + /// The key to simulate + /// Delay in ms between keydown and keyup of final keyCode. + IKeyboardSimulator DelayedModifiedKeyStrokeDown(IEnumerable modifierDikCodes, DirectInputKeyCode dikCode, int delay); + + + /// + /// 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. + /// The flow is Key Press, Modifiers KeyUp in reverse order. + /// + /// The list of modifier keys + /// The key to simulate + /// Delay in ms between keydown and keyup of final keyCode. + IKeyboardSimulator DelayedModifiedKeyStrokeUp(IEnumerable modifierDikCodes, DirectInputKeyCode dikCode, int delay); + + /// + /// 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. + /// The flow is Modifier KeyDown, Keys Press in order, Modifier KeyUp. + /// + /// The modifier key + /// The list of keys to simulate + IKeyboardSimulator ModifiedKeyStroke(DirectInputKeyCode modifierDikCode, IEnumerable dikCodes); + + /// + /// 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. + /// The flow is Modifiers KeyDown in order, Keys Press in order, Modifiers KeyUp in reverse order. + /// + /// The list of modifier keys + /// The list of keys to simulate + IKeyboardSimulator ModifiedKeyStroke(IEnumerable modifierDikCodes, IEnumerable dikCodes); + + /// + /// Simulates uninterrupted text entry via the keyboard. + /// + /// The text to be simulated. + IKeyboardSimulator TextEntry(string text); + + /// + /// Simulates a single character text entry via the keyboard. + /// + /// The unicode character to be simulated. + IKeyboardSimulator TextEntry(char character); + + /// + /// Sleeps the executing thread to create a pause between simulated inputs. + /// + /// The number of milliseconds to wait. + IKeyboardSimulator Sleep(int millsecondsTimeout); + + /// + /// Sleeps the executing thread to create a pause between simulated inputs. + /// + /// The time to wait. + IKeyboardSimulator Sleep(TimeSpan timeout); + } +} diff --git a/InputSimulatorPlus/WindowsInput/IMouseSimulator.cs b/InputSimulatorPlus/WindowsInput/IMouseSimulator.cs new file mode 100644 index 0000000..915f496 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/IMouseSimulator.cs @@ -0,0 +1,150 @@ +using System; + +namespace WindowsInput +{ + /// + /// The service contract for a mouse simulator for the Windows platform. + /// + public interface IMouseSimulator + { + /// + /// Gets or sets the amount of mouse wheel scrolling per click. The default value for this property is 120 and different values may cause some applications to interpret the scrolling differently than expected. + /// + int MouseWheelClickSize { get; set; } + + /// + /// Gets the instance for simulating Keyboard input. + /// + /// The instance. + IKeyboardSimulator Keyboard { get; } + + /// + /// Simulates mouse movement by the specified distance measured as a delta from the current mouse location in pixels. + /// + /// The distance in pixels to move the mouse horizontally. + /// The distance in pixels to move the mouse vertically. + IMouseSimulator MoveMouseBy(int pixelDeltaX, int pixelDeltaY); + + /// + /// Simulates mouse movement to the specified location on the primary display device. + /// + /// 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. + /// 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. + IMouseSimulator MoveMouseTo(double absoluteX, double absoluteY); + + /// + /// Simulates mouse movement to the specified location on the Virtual Desktop which includes all active displays. + /// + /// 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. + /// 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. + IMouseSimulator MoveMouseToPositionOnVirtualDesktop(double absoluteX, double absoluteY); + + /// + /// Simulates a mouse left button down gesture. + /// + IMouseSimulator LeftButtonDown(); + + /// + /// Simulates a mouse left button up gesture. + /// + IMouseSimulator LeftButtonUp(); + + /// + /// Simulates a mouse left button click gesture. + /// + IMouseSimulator LeftButtonClick(); + + /// + /// Simulates a mouse left button double-click gesture. + /// + IMouseSimulator LeftButtonDoubleClick(); + + /// + /// Simulates a mouse middle button down gesture. + /// + IMouseSimulator MiddleButtonDown(); + + /// + /// Simulates a mouse middle button up gesture. + /// + IMouseSimulator MiddleButtonUp(); + + /// + /// Simulates a mouse middle button click gesture. + /// + IMouseSimulator MiddleButtonClick(); + + /// + /// Simulates a mouse middle button double-click gesture. + /// + IMouseSimulator MiddleButtonDoubleClick(); + + /// + /// Simulates a mouse right button down gesture. + /// + IMouseSimulator RightButtonDown(); + + /// + /// Simulates a mouse right button up gesture. + /// + IMouseSimulator RightButtonUp(); + + /// + /// Simulates a mouse right button click gesture. + /// + IMouseSimulator RightButtonClick(); + + /// + /// Simulates a mouse right button double-click gesture. + /// + IMouseSimulator RightButtonDoubleClick(); + + /// + /// Simulates a mouse X button down gesture. + /// + /// The button id. + IMouseSimulator XButtonDown(int buttonId); + + /// + /// Simulates a mouse X button up gesture. + /// + /// The button id. + IMouseSimulator XButtonUp(int buttonId); + + /// + /// Simulates a mouse X button click gesture. + /// + /// The button id. + IMouseSimulator XButtonClick(int buttonId); + + /// + /// Simulates a mouse X button double-click gesture. + /// + /// The button id. + IMouseSimulator XButtonDoubleClick(int buttonId); + + /// + /// Simulates mouse vertical wheel scroll gesture. + /// + /// 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. + IMouseSimulator VerticalScroll(int scrollAmountInClicks); + + /// + /// Simulates a mouse horizontal wheel scroll gesture. Supported by Windows Vista and later. + /// + /// 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. + IMouseSimulator HorizontalScroll(int scrollAmountInClicks); + + /// + /// Sleeps the executing thread to create a pause between simulated inputs. + /// + /// The number of milliseconds to wait. + IMouseSimulator Sleep(int millsecondsTimeout); + + /// + /// Sleeps the executing thread to create a pause between simulated inputs. + /// + /// The time to wait. + IMouseSimulator Sleep(TimeSpan timeout); + } +} \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput/InputBuilder.cs b/InputSimulatorPlus/WindowsInput/InputBuilder.cs new file mode 100644 index 0000000..3731fde --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/InputBuilder.cs @@ -0,0 +1,576 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using WindowsInput.Native; + +namespace WindowsInput +{ + /// + /// A helper class for building a list of messages ready to be sent to the native Windows API. + /// + internal class InputBuilder : IEnumerable + { + /// + /// The public list of messages being built by this instance. + /// + private readonly List _inputList; + + /// + /// Initializes a new instance of the class. + /// + public InputBuilder() + { + _inputList = new List(); + } + + /// + /// Returns the list of messages as a of messages. + /// + /// The of messages. + public INPUT[] ToArray() + { + return _inputList.ToArray(); + } + + /// + /// Returns an enumerator that iterates through the list of messages. + /// + /// + /// A that can be used to iterate through the list of messages. + /// + /// 1 + public IEnumerator GetEnumerator() + { + return _inputList.GetEnumerator(); + } + + /// + /// Returns an enumerator that iterates through the list of messages. + /// + /// + /// An object that can be used to iterate through the list of messages. + /// + /// 2 + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + /// + /// Gets the at the specified position. + /// + /// The message at the specified position. + public INPUT this[int position] + { + get + { + return _inputList[position]; + } + } + + /// + /// Determines if the is an ExtendedKey + /// + /// The key code. + /// true if the key code is an extended key; otherwise, false. + /// + /// 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. + /// + /// See http://msdn.microsoft.com/en-us/library/ms646267(v=vs.85).aspx Section "Extended-Key Flag" + /// + public static bool IsExtendedKey(VirtualKeyCode keyCode) + { + if (keyCode == VirtualKeyCode.MENU || + //keyCode == VirtualKeyCode.LMENU || + keyCode == VirtualKeyCode.RMENU || + keyCode == VirtualKeyCode.CONTROL || + keyCode == VirtualKeyCode.RCONTROL || + keyCode == VirtualKeyCode.INSERT || + keyCode == VirtualKeyCode.DELETE || + keyCode == VirtualKeyCode.HOME || + keyCode == VirtualKeyCode.END || + keyCode == VirtualKeyCode.PRIOR || + keyCode == VirtualKeyCode.NEXT || + keyCode == VirtualKeyCode.RIGHT || + keyCode == VirtualKeyCode.UP || + keyCode == VirtualKeyCode.LEFT || + keyCode == VirtualKeyCode.DOWN || + keyCode == VirtualKeyCode.NUMLOCK || + keyCode == VirtualKeyCode.CANCEL || + keyCode == VirtualKeyCode.SNAPSHOT || + keyCode == VirtualKeyCode.DIVIDE) + { + return true; + } + else + { + return false; + } + } + + /// + /// Adds a key down to the list of messages. + /// + /// The . + /// This instance. + public InputBuilder AddKeyDown(VirtualKeyCode keyCode) + { + // The specification says Scan is unused unless we are using KEYEVENTF_UNICODE or KEYEVENTF_SCANCODE. + // However, some applications like Microsoft's Remote Desktop Client assume it is the scan code, even + // when KEYEVENTF_SCANCODE is not set. Set the value to work around these buggy apps. + ushort scan = (ushort)NativeMethods.MapVirtualKey((uint)keyCode, NativeMethods.MapVirtualKeyMapTypes.MapvkVkToVsc); + + var down = + new INPUT + { + Type = (UInt32) InputType.Keyboard, + Data = + { + Keyboard = + new KEYBDINPUT + { + KeyCode = (UInt16) keyCode, + //Scan = (UInt16)(NativeMethods.MapVirtualKey((UInt32)keyCode, 0) & 0xFFU), + //Flags = IsExtendedKey(keyCode) ? (UInt32) KeyboardFlag.ExtendedKey : 0, + Scan = scan, + Flags = (scan > 0x7F) ? (uint) KeyboardFlag.ExtendedKey : 0, + Time = 0, + ExtraInfo = IntPtr.Zero + } + } + }; + + _inputList.Add(down); + return this; + } + + /// + /// Adds a key up to the list of messages. + /// + /// The . + /// This instance. + public InputBuilder AddKeyUp(VirtualKeyCode keyCode) + { + // The specification says Scan is unused unless we are using KEYEVENTF_UNICODE or KEYEVENTF_SCANCODE. + // However, some applications like Microsoft's Remote Desktop Client assume it is the scan code, even + // when KEYEVENTF_SCANCODE is not set. Set the value to work around these buggy apps. + ushort scan = (ushort)NativeMethods.MapVirtualKey((uint)keyCode, NativeMethods.MapVirtualKeyMapTypes.MapvkVkToVsc); + var up = + new INPUT + { + Type = (UInt32) InputType.Keyboard, + Data = + { + Keyboard = + new KEYBDINPUT + { + KeyCode = (UInt16) keyCode, + //Scan = (UInt16)(NativeMethods.MapVirtualKey((UInt32)keyCode, 0) & 0xFFU), + //Flags = (UInt32) (IsExtendedKey(keyCode) + Scan = scan, + Flags = (uint)((scan > 0x7F) + ? KeyboardFlag.KeyUp | KeyboardFlag.ExtendedKey + : KeyboardFlag.KeyUp), + Time = 0, + ExtraInfo = IntPtr.Zero + } + } + }; + + _inputList.Add(up); + return this; + } + + /// + /// Adds a key press to the list of messages which is equivalent to a key down followed by a key up. + /// + /// The . + /// This instance. + public InputBuilder AddKeyPress(VirtualKeyCode keyCode) + { + AddKeyDown(keyCode); + AddKeyUp(keyCode); + return this; + } + + /// + /// Adds the character to the list of messages. + /// + /// The to be added to the list of messages. + /// This instance. + public InputBuilder AddCharacter(char character) + { + UInt16 scanCode = character; + + var down = new INPUT + { + Type = (UInt32)InputType.Keyboard, + Data = + { + Keyboard = + new KEYBDINPUT + { + KeyCode = 0, + Scan = scanCode, + Flags = (UInt32)KeyboardFlag.Unicode, + Time = 0, + ExtraInfo = IntPtr.Zero + } + } + }; + + var up = new INPUT + { + Type = (UInt32)InputType.Keyboard, + Data = + { + Keyboard = + new KEYBDINPUT + { + KeyCode = 0, + Scan = scanCode, + Flags = + (UInt32)(KeyboardFlag.KeyUp | KeyboardFlag.Unicode), + Time = 0, + ExtraInfo = IntPtr.Zero + } + } + }; + + // Handle extended keys: + // If the scan code is preceded by a prefix byte that has the value 0xE0 (224), + // we need to include the KEYEVENTF_EXTENDEDKEY flag in the Flags property. + if ((scanCode & 0xFF00) == 0xE000) + { + down.Data.Keyboard.Flags |= (UInt32)KeyboardFlag.ExtendedKey; + up.Data.Keyboard.Flags |= (UInt32)KeyboardFlag.ExtendedKey; + } + + _inputList.Add(down); + _inputList.Add(up); + return this; + } + + /// + /// Adds all of the characters in the specified of . + /// + /// The characters to add. + /// This instance. + public InputBuilder AddCharacters(IEnumerable characters) + { + foreach (var character in characters) + { + AddCharacter(character); + } + return this; + } + + /// + /// Adds the characters in the specified . + /// + /// The string of to add. + /// This instance. + public InputBuilder AddCharacters(string characters) + { + return AddCharacters(characters.ToCharArray()); + } + + /// + /// Moves the mouse relative to its current position. + /// + /// + /// + /// This instance. + public InputBuilder AddRelativeMouseMovement(int x, int y) + { + var movement = new INPUT { Type = (UInt32)InputType.Mouse }; + movement.Data.Mouse.Flags = (UInt32)MouseFlag.Move; + movement.Data.Mouse.X = x; + movement.Data.Mouse.Y = y; + + _inputList.Add(movement); + + return this; + } + + /// + /// Move the mouse to an absolute position. + /// + /// + /// + /// This instance. + public InputBuilder AddAbsoluteMouseMovement(int absoluteX, int absoluteY) + { + var movement = new INPUT { Type = (UInt32)InputType.Mouse }; + movement.Data.Mouse.Flags = (UInt32)(MouseFlag.Move | MouseFlag.Absolute); + movement.Data.Mouse.X = absoluteX; + movement.Data.Mouse.Y = absoluteY; + + _inputList.Add(movement); + + return this; + } + + /// + /// Move the mouse to the absolute position on the virtual desktop. + /// + /// + /// + /// This instance. + public InputBuilder AddAbsoluteMouseMovementOnVirtualDesktop(int absoluteX, int absoluteY) + { + var movement = new INPUT { Type = (UInt32)InputType.Mouse }; + movement.Data.Mouse.Flags = (UInt32)(MouseFlag.Move | MouseFlag.Absolute | MouseFlag.VirtualDesk); + movement.Data.Mouse.X = absoluteX; + movement.Data.Mouse.Y = absoluteY; + + _inputList.Add(movement); + + return this; + } + + /// + /// Adds a mouse button down for the specified button. + /// + /// + /// This instance. + public InputBuilder AddMouseButtonDown(MouseButton button) + { + var buttonDown = new INPUT { Type = (UInt32)InputType.Mouse }; + buttonDown.Data.Mouse.Flags = (UInt32)ToMouseButtonDownFlag(button); + + _inputList.Add(buttonDown); + + return this; + } + + /// + /// Adds a mouse button down for the specified button. + /// + /// + /// This instance. + public InputBuilder AddMouseXButtonDown(int xButtonId) + { + var buttonDown = new INPUT { Type = (UInt32)InputType.Mouse }; + buttonDown.Data.Mouse.Flags = (UInt32)MouseFlag.XDown; + buttonDown.Data.Mouse.MouseData = (UInt32)xButtonId; + _inputList.Add(buttonDown); + + return this; + } + + /// + /// Adds a mouse button up for the specified button. + /// + /// + /// This instance. + public InputBuilder AddMouseButtonUp(MouseButton button) + { + var buttonUp = new INPUT { Type = (UInt32)InputType.Mouse }; + buttonUp.Data.Mouse.Flags = (UInt32)ToMouseButtonUpFlag(button); + _inputList.Add(buttonUp); + + return this; + } + + /// + /// Adds a mouse button up for the specified button. + /// + /// + /// This instance. + public InputBuilder AddMouseXButtonUp(int xButtonId) + { + var buttonUp = new INPUT { Type = (UInt32)InputType.Mouse }; + buttonUp.Data.Mouse.Flags = (UInt32)MouseFlag.XUp; + buttonUp.Data.Mouse.MouseData = (UInt32)xButtonId; + _inputList.Add(buttonUp); + + return this; + } + + /// + /// Adds a single click of the specified button. + /// + /// + /// This instance. + public InputBuilder AddMouseButtonClick(MouseButton button) + { + return AddMouseButtonDown(button).AddMouseButtonUp(button); + } + + /// + /// Adds a single click of the specified button. + /// + /// + /// This instance. + public InputBuilder AddMouseXButtonClick(int xButtonId) + { + return AddMouseXButtonDown(xButtonId).AddMouseXButtonUp(xButtonId); + } + + /// + /// Adds a double click of the specified button. + /// + /// + /// This instance. + public InputBuilder AddMouseButtonDoubleClick(MouseButton button) + { + return AddMouseButtonClick(button).AddMouseButtonClick(button); + } + + /// + /// Adds a double click of the specified button. + /// + /// + /// This instance. + public InputBuilder AddMouseXButtonDoubleClick(int xButtonId) + { + return AddMouseXButtonClick(xButtonId).AddMouseXButtonClick(xButtonId); + } + + /// + /// Scroll the vertical mouse wheel by the specified amount. + /// + /// + /// This instance. + public InputBuilder AddMouseVerticalWheelScroll(int scrollAmount) + { + var scroll = new INPUT { Type = (UInt32)InputType.Mouse }; + scroll.Data.Mouse.Flags = (UInt32)MouseFlag.VerticalWheel; + scroll.Data.Mouse.MouseData = (UInt32)scrollAmount; + + _inputList.Add(scroll); + + return this; + } + + /// + /// Scroll the horizontal mouse wheel by the specified amount. + /// + /// + /// This instance. + public InputBuilder AddMouseHorizontalWheelScroll(int scrollAmount) + { + var scroll = new INPUT { Type = (UInt32)InputType.Mouse }; + scroll.Data.Mouse.Flags = (UInt32)MouseFlag.HorizontalWheel; + scroll.Data.Mouse.MouseData = (UInt32)scrollAmount; + + _inputList.Add(scroll); + + return this; + } + + #region DIK scancodes + /// + /// Adds a key down to the list of Input messages. + /// + /// The . + /// This instance. + public InputBuilder AddKeyDown(DirectInputKeyCode dikCode) + { + var down = + new INPUT + { + Type = (uint)InputType.Keyboard, + Data = + { + Keyboard = + new KEYBDINPUT + { + KeyCode = 0, + Scan = (ushort)dikCode, + Flags = (uint)(((ushort)dikCode > 0x7F) + ? KeyboardFlag.ScanCode | KeyboardFlag.ExtendedKey + : KeyboardFlag.ScanCode), + Time = 0, + ExtraInfo = IntPtr.Zero + } + } + }; + + _inputList.Add(down); + return this; + } + + /// + /// Adds a key up to the list of Input messages. + /// + /// The . + /// This instance. + public InputBuilder AddKeyUp(DirectInputKeyCode dikCode) + { + var up = + new INPUT + { + Type = (uint)InputType.Keyboard, + Data = + { + Keyboard = + new KEYBDINPUT + { + KeyCode = 0, + Scan = (ushort)dikCode, + Flags = (uint)(((ushort)dikCode > 0x7F) + ? KeyboardFlag.ScanCode | KeyboardFlag.KeyUp | KeyboardFlag.ExtendedKey + : KeyboardFlag.ScanCode | KeyboardFlag.KeyUp), + Time = 0, + ExtraInfo = IntPtr.Zero + } + } + }; + + _inputList.Add(up); + return this; + } + + /// + /// Adds a key press to the list of Input messages which is equivalent to a key down followed by a key up. + /// + /// The . + /// This instance. + public InputBuilder AddKeyPress(DirectInputKeyCode dikCode) + { + AddKeyDown(dikCode); + AddKeyUp(dikCode); + return this; + } + #endregion + + private static MouseFlag ToMouseButtonDownFlag(MouseButton button) + { + switch (button) + { + case MouseButton.LeftButton: + return MouseFlag.LeftDown; + + case MouseButton.MiddleButton: + return MouseFlag.MiddleDown; + + case MouseButton.RightButton: + return MouseFlag.RightDown; + + default: + return MouseFlag.LeftDown; + } + } + + private static MouseFlag ToMouseButtonUpFlag(MouseButton button) + { + switch (button) + { + case MouseButton.LeftButton: + return MouseFlag.LeftUp; + + case MouseButton.MiddleButton: + return MouseFlag.MiddleUp; + + case MouseButton.RightButton: + return MouseFlag.RightUp; + + default: + return MouseFlag.LeftUp; + } + } + } + +} \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput/InputSimulator.cs b/InputSimulatorPlus/WindowsInput/InputSimulator.cs new file mode 100644 index 0000000..ca051d8 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/InputSimulator.cs @@ -0,0 +1,75 @@ +using System; + +namespace WindowsInput +{ + /// + /// Implements the interface to simulate Keyboard and Mouse input and provide the state of those input devices. + /// + public class InputSimulator : IInputSimulator + { + /// + /// The instance to use for simulating keyboard input. + /// + private readonly IKeyboardSimulator _keyboardSimulator; + + /// + /// The instance to use for simulating mouse input. + /// + private readonly IMouseSimulator _mouseSimulator; + + /// + /// The instance to use for interpreting the state of the input devices. + /// + private readonly IInputDeviceStateAdaptor _inputDeviceState; + + /// + /// Initializes a new instance of the class using the specified , and instances. + /// + /// The instance to use for simulating keyboard input. + /// The instance to use for simulating mouse input. + /// The instance to use for interpreting the state of input devices. + public InputSimulator(IKeyboardSimulator keyboardSimulator, IMouseSimulator mouseSimulator, IInputDeviceStateAdaptor inputDeviceStateAdaptor) + { + _keyboardSimulator = keyboardSimulator; + _mouseSimulator = mouseSimulator; + _inputDeviceState = inputDeviceStateAdaptor; + } + + /// + /// Initializes a new instance of the class using the default , and instances. + /// + public InputSimulator() + { + _keyboardSimulator = new KeyboardSimulator(this); + _mouseSimulator = new MouseSimulator(this); + _inputDeviceState = new WindowsInputDeviceStateAdaptor(); + } + + /// + /// Gets the instance for simulating Keyboard input. + /// + /// The instance. + public IKeyboardSimulator Keyboard + { + get { return _keyboardSimulator; } + } + + /// + /// Gets the instance for simulating Mouse input. + /// + /// The instance. + public IMouseSimulator Mouse + { + get { return _mouseSimulator; } + } + + /// + /// Gets the instance for determining the state of the various input devices. + /// + /// The instance. + public IInputDeviceStateAdaptor InputDeviceState + { + get { return _inputDeviceState; } + } + } +} \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput/KeyboardSimulator.cs b/InputSimulatorPlus/WindowsInput/KeyboardSimulator.cs new file mode 100644 index 0000000..f5ca121 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/KeyboardSimulator.cs @@ -0,0 +1,481 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using WindowsInput.Native; +using System.Linq; + +namespace WindowsInput +{ + /// + /// Implements the interface by calling the an to simulate Keyboard gestures. + /// + public class KeyboardSimulator : IKeyboardSimulator + { + private readonly IInputSimulator _inputSimulator; + + /// + /// The instance of the to use for dispatching messages. + /// + private readonly IInputMessageDispatcher _messageDispatcher; + + /// + /// Initializes a new instance of the class using an instance of a for dispatching messages. + /// + /// The that owns this instance. + public KeyboardSimulator(IInputSimulator inputSimulator) + { + if (inputSimulator == null) throw new ArgumentNullException("inputSimulator"); + + _inputSimulator = inputSimulator; + _messageDispatcher = new WindowsInputMessageDispatcher(); + } + + /// + /// Initializes a new instance of the class using the specified for dispatching messages. + /// + /// The that owns this instance. + /// The to use for dispatching messages. + /// If null is passed as the . + internal KeyboardSimulator(IInputSimulator inputSimulator, IInputMessageDispatcher messageDispatcher) + { + if (inputSimulator == null) throw new ArgumentNullException("inputSimulator"); + + if (messageDispatcher == null) + throw new InvalidOperationException( + string.Format("The {0} cannot operate with a null {1}. Please provide a valid {1} instance to use for dispatching {2} messages.", + typeof(KeyboardSimulator).Name, typeof(IInputMessageDispatcher).Name, typeof(INPUT).Name)); + + _inputSimulator = inputSimulator; + _messageDispatcher = messageDispatcher; + } + + /// + /// Gets the instance for simulating Mouse input. + /// + /// The instance. + public IMouseSimulator Mouse { get { return _inputSimulator.Mouse; } } + + private void ModifiersDown(InputBuilder builder, IEnumerable modifierKeyCodes) + { + if (modifierKeyCodes == null) return; + foreach (var key in modifierKeyCodes) builder.AddKeyDown(key); + } + + private void ModifiersUp(InputBuilder builder, IEnumerable modifierKeyCodes) + { + if (modifierKeyCodes == null) return; + + // Key up in reverse (I miss LINQ) + var stack = new Stack(modifierKeyCodes); + while (stack.Count > 0) builder.AddKeyUp(stack.Pop()); + } + + private void KeysPress(InputBuilder builder, IEnumerable keyCodes) + { + if (keyCodes == null) return; + foreach (var key in keyCodes) builder.AddKeyPress(key); + } + + /// + /// Sends the list of messages using the instance. + /// + /// The of messages to send. + private void SendSimulatedInput(INPUT[] inputList) + { + _messageDispatcher.DispatchInput(inputList); + } + + /// + /// Calls the Win32 SendInput method to simulate a KeyDown. + /// + /// The to press + public IKeyboardSimulator KeyDown(VirtualKeyCode keyCode) + { + var inputList = new InputBuilder().AddKeyDown(keyCode).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Calls the Win32 SendInput method to simulate a KeyUp. + /// + /// The to lift up + public IKeyboardSimulator KeyUp(VirtualKeyCode keyCode) + { + var inputList = new InputBuilder().AddKeyUp(keyCode).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Calls the Win32 SendInput method with a KeyDown and KeyUp message in the same input sequence in order to simulate a Key PRESS. + /// + /// The to press + public IKeyboardSimulator KeyPress(VirtualKeyCode keyCode) + { + var inputList = new InputBuilder().AddKeyPress(keyCode).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates a key press for each of the specified key codes in the order they are specified. + /// + /// + public IKeyboardSimulator KeyPress(params VirtualKeyCode[] keyCodes) + { + var builder = new InputBuilder(); + KeysPress(builder, keyCodes); + SendSimulatedInput(builder.ToArray()); + return this; + } + + /// + /// Simulates a simple modified keystroke like CTRL-C where CTRL is the modifierKey and C is the key. + /// The flow is Modifier KeyDown, Key Press, Modifier KeyUp. + /// + /// The modifier key + /// The key to simulate + public IKeyboardSimulator ModifiedKeyStroke(VirtualKeyCode modifierKeyCode, VirtualKeyCode keyCode) + { + ModifiedKeyStroke(new[] { modifierKeyCode }, new[] { keyCode }); + return this; + } + + /// + /// 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. + /// The flow is Modifiers KeyDown in order, Key Press, Modifiers KeyUp in reverse order. + /// + /// The list of modifier keys + /// The key to simulate + public IKeyboardSimulator ModifiedKeyStroke(IEnumerable modifierKeyCodes, VirtualKeyCode keyCode) + { + ModifiedKeyStroke(modifierKeyCodes, new[] {keyCode}); + return this; + } + + /// + /// 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. + /// The flow is Modifier KeyDown, Keys Press in order, Modifier KeyUp. + /// + /// The modifier key + /// The list of keys to simulate + public IKeyboardSimulator ModifiedKeyStroke(VirtualKeyCode modifierKey, IEnumerable keyCodes) + { + ModifiedKeyStroke(new [] {modifierKey}, keyCodes); + return this; + } + + /// + /// 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. + /// The flow is Modifiers KeyDown in order, Keys Press in order, Modifiers KeyUp in reverse order. + /// + /// The list of modifier keys + /// The list of keys to simulate + public IKeyboardSimulator ModifiedKeyStroke(IEnumerable modifierKeyCodes, IEnumerable keyCodes) + { + var builder = new InputBuilder(); + ModifiersDown(builder, modifierKeyCodes); + KeysPress(builder, keyCodes); + ModifiersUp(builder, modifierKeyCodes); + + SendSimulatedInput(builder.ToArray()); + return this; + } + + /// + /// Manually creates a keystroke and delays the keyup by a specified number of ms. + /// The flow is Modifiers KeyDown in order, Keys Press in order, Modifiers KeyUp in reverse order. + /// + /// The list of modifier keys + /// The list of keys to simulate + /// Delay in ms between keydown and keyup of final keyCode. 50ms should be minimum + public IKeyboardSimulator DelayedModifiedKeyStroke(IEnumerable modifierKeyCodes, IEnumerable keyCodes, int delay) + { + foreach (var keyCode in modifierKeyCodes) + { + var inputList = new InputBuilder().AddKeyDown(keyCode).ToArray(); + SendSimulatedInput(inputList); + } + + foreach (var keyCode in keyCodes) + { + var inputList = new InputBuilder().AddKeyDown(keyCode).ToArray(); + SendSimulatedInput(inputList); + } + + Thread.Sleep(delay); + + + foreach (var keyCode in keyCodes.Reverse()) + { + var inputList = new InputBuilder().AddKeyUp(keyCode).ToArray(); + SendSimulatedInput(inputList); + } + + foreach (var keyCode in modifierKeyCodes.Reverse()) + { + var inputList = new InputBuilder().AddKeyUp(keyCode).ToArray(); + SendSimulatedInput(inputList); + } + + return this; + } + + /// + /// Calls the Win32 SendInput method with a stream of KeyDown and KeyUp messages in order to simulate uninterrupted text entry via the keyboard. + /// + /// The text to be simulated. + public IKeyboardSimulator TextEntry(string text) + { + 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"); + var inputList = new InputBuilder().AddCharacters(text).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates a single character text entry via the keyboard. + /// + /// The unicode character to be simulated. + public IKeyboardSimulator TextEntry(char character) + { + var inputList = new InputBuilder().AddCharacter(character).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Sleeps the executing thread to create a pause between simulated inputs. + /// + /// The number of milliseconds to wait. + public IKeyboardSimulator Sleep(int millsecondsTimeout) + { + Thread.Sleep(millsecondsTimeout); + return this; + } + + /// + /// Sleeps the executing thread to create a pause between simulated inputs. + /// + /// The time to wait. + public IKeyboardSimulator Sleep(TimeSpan timeout) + { + Thread.Sleep(timeout); + return this; + } + + + #region DIK scancodes + /// + /// Calls the Win32 SendInput method to simulate a KeyDown. + /// + /// The to press + public IKeyboardSimulator KeyDown(DirectInputKeyCode dikCode) + { + var inputList = new InputBuilder().AddKeyDown(dikCode).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Calls the Win32 SendInput method to simulate a KeyUp. + /// + /// The to lift up + public IKeyboardSimulator KeyUp(DirectInputKeyCode dikCode) + { + var inputList = new InputBuilder().AddKeyUp(dikCode).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Calls the Win32 SendInput method with a KeyDown and KeyUp message in the same input sequence in order to simulate a Key PRESS. + /// + /// The to press + public IKeyboardSimulator KeyPress(DirectInputKeyCode dikCode) + { + var inputList = + new InputBuilder() + .AddKeyDown(dikCode) + .AddKeyUp(dikCode) + .ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Calls the Win32 SendInput method with a KeyDown and KeyUp message in the same input sequence in order to simulate a Key PRESS. + /// + /// The to press + /// Delay in ms between keydown and keyup of final keyCode. 50ms should be minimum + public IKeyboardSimulator DelayedKeyPress(DirectInputKeyCode dikCode, int delay) + { + DelayedKeyPressDown(dikCode, delay); + + Thread.Sleep(delay); + + DelayedKeyPressUp(dikCode, delay); + + return this; + } + + /// + /// Calls the Win32 SendInput method with a KeyDown message + /// + /// The to press + /// Delay in ms between keydown and keyup of final keyCode. 50ms should be minimum + public IKeyboardSimulator DelayedKeyPressDown(DirectInputKeyCode dikCode, int delay) + { + var inputList1 = new InputBuilder().AddKeyDown(dikCode).ToArray(); + SendSimulatedInput(inputList1); + + return this; + } + + /// + /// Calls the Win32 SendInput method with a KeyUp message + /// + /// The to press + /// Delay in ms between keydown and keyup of final keyCode. 50ms should be minimum + public IKeyboardSimulator DelayedKeyPressUp(DirectInputKeyCode dikCode, int delay) + { + var inputList2 = new InputBuilder().AddKeyUp(dikCode).ToArray(); + SendSimulatedInput(inputList2); + + return this; + } + + /// + /// Simulates a simple modified keystroke like CTRL-C where CTRL is the modifierKey and C is the key. + /// The flow is Modifier KeyDown, Key Press, Modifier KeyUp. + /// + /// The modifier key + /// The key to simulate + public IKeyboardSimulator ModifiedKeyStroke(DirectInputKeyCode modifierDikCode, DirectInputKeyCode dikCode) + { + ModifiedKeyStroke(new[] { modifierDikCode }, new[] { dikCode }); + return this; + } + + /// + /// 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. + /// The flow is Modifiers KeyDown in order, Key Press, Modifiers KeyUp in reverse order. + /// + /// The list of modifier keys + /// The key to simulate + public IKeyboardSimulator ModifiedKeyStroke(IEnumerable modifierDikCodes, DirectInputKeyCode dikCode) + { + ModifiedKeyStroke(modifierDikCodes, new[] { dikCode }); + return this; + } + + /// + /// 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. + /// The flow is Modifier KeyDown, Keys Press in order, Modifier KeyUp. + /// + /// The modifier key + /// The list of keys to simulate + public IKeyboardSimulator ModifiedKeyStroke(DirectInputKeyCode modifierDikCode, IEnumerable dikCodes) + { + ModifiedKeyStroke(new[] { modifierDikCode }, dikCodes); + return this; + } + + /// + /// 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. + /// The flow is Modifiers KeyDown in order, Keys Press in order, Modifiers KeyUp in reverse order. + /// + /// The list of modifier keys + /// The list of keys to simulate + public IKeyboardSimulator ModifiedKeyStroke(IEnumerable modifierDikCodes, IEnumerable dikCodes) + { + var builder = new InputBuilder(); + ModifiersDown(builder, modifierDikCodes); + KeysPress(builder, dikCodes); + ModifiersUp(builder, modifierDikCodes); + SendSimulatedInput(builder.ToArray()); + return this; + } + + /// + /// 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. + /// The flow is Modifiers KeyDown in order, Keys Press in order, Modifiers KeyUp in reverse order. + /// + /// The list of modifier keys + /// The list of keys to simulate + /// Delay in ms between keydown and keyup of final keyCode. 50ms should be minimum + public IKeyboardSimulator DelayedModifiedKeyStroke(IEnumerable modifierDikCodes, DirectInputKeyCode dikCode, int delay) + { + DelayedModifiedKeyStrokeDown(modifierDikCodes, dikCode, delay); + + Thread.Sleep(delay); + + DelayedModifiedKeyStrokeUp(modifierDikCodes, dikCode, delay); + + return this; + } + + /// + /// 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. + /// The flow is Modifiers KeyDown in order, Keys Press in order + /// + /// The list of modifier keys + /// The list of keys to simulate + /// Delay in ms between keydown and keyup of final keyCode. 50ms should be minimum + public IKeyboardSimulator DelayedModifiedKeyStrokeDown(IEnumerable modifierDikCodes, DirectInputKeyCode dikCode, int delay) + { + foreach (var keyCode in modifierDikCodes) + { + var inputList = new InputBuilder().AddKeyDown(keyCode).ToArray(); + SendSimulatedInput(inputList); + } + + KeyDown(dikCode); + + return this; + } + + /// + /// 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. + /// The flow is Keys Press in order, Modifiers KeyUp in reverse order. + /// + /// The list of modifier keys + /// The list of keys to simulate + /// Delay in ms between keydown and keyup of final keyCode. 50ms should be minimum + public IKeyboardSimulator DelayedModifiedKeyStrokeUp(IEnumerable modifierDikCodes, DirectInputKeyCode dikCode, int delay) + { + KeyUp(dikCode); + + foreach (var keyCode in modifierDikCodes.Reverse()) + { + var inputList = new InputBuilder().AddKeyUp(keyCode).ToArray(); + SendSimulatedInput(inputList); + } + + return this; + } + + private void ModifiersDown(InputBuilder builder, IEnumerable modifierDikCodes) + { + if (modifierDikCodes == null) return; + foreach (var dik in modifierDikCodes) builder.AddKeyDown(dik); + } + + private void ModifiersUp(InputBuilder builder, IEnumerable modifierDikCodes) + { + if (modifierDikCodes == null) return; + + // Key up in reverse (I miss LINQ) + var stack = new Stack(modifierDikCodes); + while (stack.Count > 0) builder.AddKeyUp(stack.Pop()); + } + + private void KeysPress(InputBuilder builder, IEnumerable dikCodes) + { + if (dikCodes == null) return; + foreach (var dik in dikCodes) builder.AddKeyPress(dik); + } + #endregion + } +} \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput/MouseButton.cs b/InputSimulatorPlus/WindowsInput/MouseButton.cs new file mode 100644 index 0000000..b96ddab --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/MouseButton.cs @@ -0,0 +1,23 @@ +namespace WindowsInput +{ + /// + /// The mouse button + /// + public enum MouseButton + { + /// + /// Left mouse button + /// + LeftButton, + + /// + /// Middle mouse button + /// + MiddleButton, + + /// + /// Right moust button + /// + RightButton, + } +} \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput/MouseSimulator.cs b/InputSimulatorPlus/WindowsInput/MouseSimulator.cs new file mode 100644 index 0000000..084ca69 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/MouseSimulator.cs @@ -0,0 +1,313 @@ +using System; +using System.Threading; +using WindowsInput.Native; + +namespace WindowsInput +{ + /// + /// Implements the interface by calling the an to simulate Mouse gestures. + /// + public class MouseSimulator : IMouseSimulator + { + /// + /// Gets or sets the amount of mouse wheel scrolling per click. The default value for this property is 120 and different values may cause some applications to interpret the scrolling differently than expected. + /// + public int MouseWheelClickSize { get; set; } = 120; + + private readonly IInputSimulator _inputSimulator; + + /// + /// The instance of the to use for dispatching messages. + /// + private readonly IInputMessageDispatcher _messageDispatcher; + + /// + /// Initializes a new instance of the class using an instance of a for dispatching messages. + /// + /// The that owns this instance. + public MouseSimulator(IInputSimulator inputSimulator) + { + if (inputSimulator == null) throw new ArgumentNullException("inputSimulator"); + + _inputSimulator = inputSimulator; + _messageDispatcher = new WindowsInputMessageDispatcher(); + } + + /// + /// Initializes a new instance of the class using the specified for dispatching messages. + /// + /// The that owns this instance. + /// The to use for dispatching messages. + /// If null is passed as the . + internal MouseSimulator(IInputSimulator inputSimulator, IInputMessageDispatcher messageDispatcher) + { + if (inputSimulator == null) + throw new ArgumentNullException("inputSimulator"); + + if (messageDispatcher == null) + throw new InvalidOperationException( + string.Format("The {0} cannot operate with a null {1}. Please provide a valid {1} instance to use for dispatching {2} messages.", + typeof(MouseSimulator).Name, typeof(IInputMessageDispatcher).Name, typeof(INPUT).Name)); + + _inputSimulator = inputSimulator; + _messageDispatcher = messageDispatcher; + } + + /// + /// Gets the instance for simulating Keyboard input. + /// + /// The instance. + public IKeyboardSimulator Keyboard { get { return _inputSimulator.Keyboard; } } + + /// + /// Sends the list of messages using the instance. + /// + /// The of messages to send. + private void SendSimulatedInput(INPUT[] inputList) + { + _messageDispatcher.DispatchInput(inputList); + } + + /// + /// Simulates mouse movement by the specified distance measured as a delta from the current mouse location in pixels. + /// + /// The distance in pixels to move the mouse horizontally. + /// The distance in pixels to move the mouse vertically. + public IMouseSimulator MoveMouseBy(int pixelDeltaX, int pixelDeltaY) + { + var inputList = new InputBuilder().AddRelativeMouseMovement(pixelDeltaX, pixelDeltaY).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates mouse movement to the specified location on the primary display device. + /// + /// 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. + /// 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. + public IMouseSimulator MoveMouseTo(double absoluteX, double absoluteY) + { + var inputList = new InputBuilder().AddAbsoluteMouseMovement((int)Math.Truncate(absoluteX), (int)Math.Truncate(absoluteY)).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates mouse movement to the specified location on the Virtual Desktop which includes all active displays. + /// + /// 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. + /// 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. + public IMouseSimulator MoveMouseToPositionOnVirtualDesktop(double absoluteX, double absoluteY) + { + var inputList = new InputBuilder().AddAbsoluteMouseMovementOnVirtualDesktop((int)Math.Truncate(absoluteX), (int)Math.Truncate(absoluteY)).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates a mouse left button down gesture. + /// + public IMouseSimulator LeftButtonDown() + { + var inputList = new InputBuilder().AddMouseButtonDown(MouseButton.LeftButton).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates a mouse left button up gesture. + /// + public IMouseSimulator LeftButtonUp() + { + var inputList = new InputBuilder().AddMouseButtonUp(MouseButton.LeftButton).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates a mouse left-click gesture. + /// + public IMouseSimulator LeftButtonClick() + { + var inputList = new InputBuilder().AddMouseButtonClick(MouseButton.LeftButton).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates a mouse left button double-click gesture. + /// + public IMouseSimulator LeftButtonDoubleClick() + { + var inputList = new InputBuilder().AddMouseButtonDoubleClick(MouseButton.LeftButton).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates a mouse middle button down gesture. + /// + public IMouseSimulator MiddleButtonDown() + { + var inputList = new InputBuilder().AddMouseButtonDown(MouseButton.MiddleButton).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates a mouse middle button up gesture. + /// + public IMouseSimulator MiddleButtonUp() + { + var inputList = new InputBuilder().AddMouseButtonUp(MouseButton.MiddleButton).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates a mouse middle button click gesture. + /// + public IMouseSimulator MiddleButtonClick() + { + var inputList = new InputBuilder().AddMouseButtonClick(MouseButton.MiddleButton).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates a mouse middle button double click gesture. + /// + public IMouseSimulator MiddleButtonDoubleClick() + { + var inputList = new InputBuilder().AddMouseButtonDoubleClick(MouseButton.MiddleButton).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates a mouse right button down gesture. + /// + public IMouseSimulator RightButtonDown() + { + var inputList = new InputBuilder().AddMouseButtonDown(MouseButton.RightButton).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates a mouse right button up gesture. + /// + public IMouseSimulator RightButtonUp() + { + var inputList = new InputBuilder().AddMouseButtonUp(MouseButton.RightButton).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates a mouse right button click gesture. + /// + public IMouseSimulator RightButtonClick() + { + var inputList = new InputBuilder().AddMouseButtonClick(MouseButton.RightButton).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates a mouse right button double-click gesture. + /// + public IMouseSimulator RightButtonDoubleClick() + { + var inputList = new InputBuilder().AddMouseButtonDoubleClick(MouseButton.RightButton).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates a mouse X button down gesture. + /// + /// The button id. + public IMouseSimulator XButtonDown(int buttonId) + { + var inputList = new InputBuilder().AddMouseXButtonDown(buttonId).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates a mouse X button up gesture. + /// + /// The button id. + public IMouseSimulator XButtonUp(int buttonId) + { + var inputList = new InputBuilder().AddMouseXButtonUp(buttonId).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates a mouse X button click gesture. + /// + /// The button id. + public IMouseSimulator XButtonClick(int buttonId) + { + var inputList = new InputBuilder().AddMouseXButtonClick(buttonId).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates a mouse X button double-click gesture. + /// + /// The button id. + public IMouseSimulator XButtonDoubleClick(int buttonId) + { + var inputList = new InputBuilder().AddMouseXButtonDoubleClick(buttonId).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates mouse vertical wheel scroll gesture. + /// + /// 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. + public IMouseSimulator VerticalScroll(int scrollAmountInClicks) + { + var inputList = new InputBuilder().AddMouseVerticalWheelScroll(scrollAmountInClicks * MouseWheelClickSize).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Simulates a mouse horizontal wheel scroll gesture. Supported by Windows Vista and later. + /// + /// 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. + public IMouseSimulator HorizontalScroll(int scrollAmountInClicks) + { + var inputList = new InputBuilder().AddMouseHorizontalWheelScroll(scrollAmountInClicks * MouseWheelClickSize).ToArray(); + SendSimulatedInput(inputList); + return this; + } + + /// + /// Sleeps the executing thread to create a pause between simulated inputs. + /// + /// The number of milliseconds to wait. + public IMouseSimulator Sleep(int millsecondsTimeout) + { + Thread.Sleep(millsecondsTimeout); + return this; + } + + /// + /// Sleeps the executing thread to create a pause between simulated inputs. + /// + /// The time to wait. + public IMouseSimulator Sleep(TimeSpan timeout) + { + Thread.Sleep(timeout); + return this; + } + } +} \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput/Native/DirectInputKeyCode.cs b/InputSimulatorPlus/WindowsInput/Native/DirectInputKeyCode.cs new file mode 100644 index 0000000..3ee73ab --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/Native/DirectInputKeyCode.cs @@ -0,0 +1,925 @@ +namespace WindowsInput.Native +{ + /// + /// The list of DirectInput keyboard scan codes from dinput.h in dxsdk + /// + public enum DirectInputKeyCode + { + /// + /// Escape key + /// + DikEscape = 0x01, + /// + /// '1' key on main keyboard + /// + Dik1 = 0x02, + /// + /// '2' key on main keyboard + /// + Dik2 = 0x03, + /// + /// '3' key on main keyboard + /// + Dik3 = 0x04, + /// + /// '4' key on main keyboard + /// + Dik4 = 0x05, + /// + /// '5' key on main keyboard + /// + Dik5 = 0x06, + /// + /// '6' key on main keyboard + /// + Dik6 = 0x07, + /// + /// '7' key on main keyboard + /// + Dik7 = 0x08, + /// + /// '8' key on main keyboard + /// + Dik8 = 0x09, + /// + /// '9' key on main keyboard + /// + Dik9 = 0x0A, + /// + /// '0' key on main keyboard + /// + Dik0 = 0x0B, + /// + /// '-' key on main keyboard + /// + DikMinus = 0x0C, + /// + /// '=' key + /// + DikEquals = 0x0D, + /// + /// Backspace key + /// + DikBack = 0x0E, + /// + /// Tab key + /// + DikTab = 0x0F, + /// + /// 'q' key + /// + DikQ = 0x10, + /// + /// 'w' key + /// + DikW = 0x11, + /// + /// 'e' key + /// + DikE = 0x12, + /// + /// 'r' key + /// + DikR = 0x13, + /// + /// 't' key + /// + DikT = 0x14, + /// + /// 'y' key + /// + DikY = 0x15, + /// + /// 'u' key + /// + DikU = 0x16, + /// + /// 'i' key + /// + DikI = 0x17, + /// + /// 'o' key + /// + DikO = 0x18, + /// + /// 'p' key + /// + DikP = 0x19, + /// + /// '[' key??? + /// + DikLbracket = 0x1A, + /// + /// ']' key??? + /// + DikRbracket = 0x1B, + /// + /// 'enter' key on main keyboard + /// + DikReturn = 0x1C, + /// + /// Left control key + /// + DikLcontrol = 0x1D, + /// + /// 'a' key + /// + DikA = 0x1E, + /// + /// 's' key + /// + DikS = 0x1F, + /// + /// 'd' key + /// + DikD = 0x20, + /// + /// 'f' key + /// + DikF = 0x21, + /// + /// 'g' key + /// + DikG = 0x22, + /// + /// 'h' key + /// + DikH = 0x23, + /// + /// 'j' key + /// + DikJ = 0x24, + /// + /// 'k' key + /// + DikK = 0x25, + /// + /// 'l' key + /// + DikL = 0x26, + /// + /// ';' key + /// + DikSemicolon = 0x27, + /// + /// ' key + /// + DikApostrophe = 0x28, + /// + /// '`' key (Accent grave) + /// + DikGrave = 0x29, + /// + /// Left shift key + /// + DikLshift = 0x2A, + /// + /// '\' key + /// + DikBackslash = 0x2B, + /// + /// 'z' key + /// + DikZ = 0x2C, + /// + /// 'x' key + /// + DikX = 0x2D, + /// + /// 'c' key + /// + DikC = 0x2E, + /// + /// 'v' key + /// + DikV = 0x2F, + /// + /// 'b' key + /// + DikB = 0x30, + /// + /// 'n' key + /// + DikN = 0x31, + /// + /// 'm' key + /// + DikM = 0x32, + /// + /// ',' key + /// + DikComma = 0x33, + /// + /// '.' key on main keyboard + /// + DikPeriod = 0x34, + /// + /// '/' key on main keyboard + /// + DikSlash = 0x35, + /// + /// Right shift key + /// + DikRshift = 0x36, + /// + /// '*' key on numeric keypad + /// + DikMultiply = 0x37, + /// + /// Left alt key + /// + DikLmenu = 0x38, + /// + /// ' ' key + /// + DikSpace = 0x39, + /// + /// Caps lock key + /// + DikCapital = 0x3A, + /// + /// 'F1' key + /// + DikF1 = 0x3B, + /// + /// 'F2' key + /// + DikF2 = 0x3C, + /// + /// 'F3' key + /// + DikF3 = 0x3D, + /// + /// 'F4' key + /// + DikF4 = 0x3E, + /// + /// 'F5' key + /// + DikF5 = 0x3F, + /// + /// 'F6' key + /// + DikF6 = 0x40, + /// + /// 'F7' key + /// + DikF7 = 0x41, + /// + /// 'F8' key + /// + DikF8 = 0x42, + /// + /// 'F9' key + /// + DikF9 = 0x43, + /// + /// 'F10' key + /// + DikF10 = 0x44, + /// + /// Numlock key + /// + DikNumlock = 0x45, + /// + /// Scroll lock key + /// + DikScroll = 0x46 /* Scroll Lock */, + /// + /// '7' key on numeric keypad + /// + DikNumpad7 = 0x47, + /// + /// '8' key on numeric keypad + /// + DikNumpad8 = 0x48, + /// + /// '9' key on numeric keypad + /// + DikNumpad9 = 0x49, + /// + /// '-' key on numeric keypad + /// + DikSubtract = 0x4A, + /// + /// '4' key on numeric keypad + /// + DikNumpad4 = 0x4B, + /// + /// '5' key on numeric keypad + /// + DikNumpad5 = 0x4C, + /// + /// '6' key on numeric keypad + /// + DikNumpad6 = 0x4D, + /// + /// '+' key on numeric keypad + /// + DikAdd = 0x4E, + /// + /// '1' key on numeric keypad + /// + DikNumpad1 = 0x4F, + /// + /// '2' key on numeric keypad + /// + DikNumpad2 = 0x50, + /// + /// '3' key on numeric keypad + /// + DikNumpad3 = 0x51, + /// + /// '0' key on numeric keypad + /// + DikNumpad0 = 0x52, + /// + /// '.' key on numeric keypad + /// + DikDecimal = 0x53, + /// + /// PrintScreen key + /// + DikPrintscreen = 0x54, + /// + /// <> or \| on RT 102-key keyboard (Non-U.S.) + /// + DikOem102 = 0x56, + /// + /// 'F11' key + /// + DikF11 = 0x57, + /// + /// 'F12' key + /// + DikF12 = 0x58, + /// + /// 'F12' key + /// + DikNumeric5 = 0x59, + /// + /// OEM key (VirtualKeyCode 0xEE) + /// + DikOemEe = 0x5A, + /// + /// OEM key (VirtualKeyCode 0xF1) + /// + DikOemF1 = 0x5B, + /// + /// OEM key (VirtualKeyCode 0xF1) + /// + DikOemEa = 0x5C, + /// + /// Erase EOF key + /// + DikEraseEof = 0x5D, + /// + /// OEM key (VirtualKeyCode 0xF5) + /// + DikOemF5 = 0x5E, + /// + /// OEM key (VirtualKeyCode 0xF3) + /// + DikOemF3 = 0x5F, + /// + /// 'Zoom' key + /// + DikZoom = 0x62, + /// + /// 'HELP' key + /// + DikHelp = 0x63, + /// + /// 'F13' key (NEC PC98) + /// + DikF13 = 0x64, + /// + /// 'F14' key (NEC PC98) + /// + DikF14 = 0x65, + /// + /// 'F15' key (NEC PC98) + /// + DikF15 = 0x66, + /// + /// 'F16' key + /// + DikF16 = 0x67, + /// + /// 'F16' key + /// + DikF17 = 0x68, + /// + /// 'F16' key + /// + DikF18 = 0x69, + /// + /// 'F16' key + /// + DikF19 = 0x6A, + /// + /// 'F16' key + /// + DikF20 = 0x6B, + /// + /// 'F16' key + /// + DikF21 = 0x6C, + /// + /// 'F16' key + /// + DikF22 = 0x6D, + /// + /// 'F16' key + /// + DikF23 = 0x6E, + /// + /// OEM key (VirtualKeyCode 0xED) + /// + DikOemEd = 0x6F, + /// + /// Japanese keyboard + /// + DikKana = 0x70, + /// + /// OEM key (VirtualKeyCode 0xE9) + /// + DikOemE9 = 0x71, + /// + /// /? on Brazilian keyboard + /// + DikAbntC1 = 0x73, + /// + /// F24 key + /// + DikF24 = 0x76, + /// + /// Japanese keyboard + /// + DikConvert = 0x79, + /// + /// Japanese keyboard + /// + DikNoconvert = 0x7B, + /// + /// Japanese keyboard + /// + DikYen = 0x7D, + /// + /// Numpad . on Brazilian keyboard + /// + DikAbntC2 = 0x7E, + /// + /// '=' on numeric keypad (NEC PC98) + /// + DikNumpadequals = 0x8D, + /// + /// Previous Track key (DIK_CIRCUMFLEX on Japanese keyboard) + /// + DikPrevtrack = 0x90, + /// + /// NEC PC98 + /// + DikAt = 0x91, + /// + /// NEC PC98 + /// + DikColon = 0x92, + /// + /// NEC PC98 + /// + DikUnderline = 0x93, + /// + /// Japanese keyboard + /// + DikKanji = 0x94, + /// + /// NEC PC98 + /// + DikStop = 0x95, + /// + /// Japan AX + /// + DikAx = 0x96, + /// + /// J3100 + /// + DikUnlabeled = 0x97, + /// + /// Next Track key + /// + DikNexttrack = 0x99, + /// + /// Enter key on numeric keypad + /// + DikNumpadenter = 0x9C, + /// + /// Right control key + /// + DikRcontrol = 0x9D, + /// + /// Mute key + /// + DikMute = 0xA0, + /// + /// Calculator key + /// + DikCalculator = 0xA1, + /// + /// Play/Pause key + /// + DikPlaypause = 0xA2, + /// + /// Media Stop key + /// + DikMediastop = 0xA4, + /// + /// Volume down key + /// + DikVolumedown = 0xAE, + /// + /// Volume up key + /// + DikVolumeup = 0xB0, + /// + /// Web home key + /// + DikWebhome = 0xB2, + /// + /// ',' key on numeric keypad + /// + DikNumpadcomma = 0xB3, + /// + /// '/' key on numeric keypad + /// + DikDivide = 0xB5, + /// + /// ??? + /// + DikSysrq = 0xB7, + /// + /// Right alt key + /// + DikRmenu = 0xB8, + /// + /// Pause key + /// + DikPause = 0xC5, + /// + /// Home key on arrow keypad + /// + DikHome = 0xC7, + /// + /// Up arrow key on arrow keypad + /// + DikUp = 0xC8, + /// + /// PageUp key on arrow keypad + /// + DikPrior = 0xC9, + /// + /// Left arrow key on arrow keypad + /// + DikLeft = 0xCB, + /// + /// Right arrow key on arrow keypad + /// + DikRight = 0xCD, + /// + /// End key on arrow keypad + /// + DikEnd = 0xCF, + /// + /// Down arrow key on arrow keypad + /// + DikDown = 0xD0, + /// + /// PageDown key on arrow keypad + /// + DikNext = 0xD1, + /// + /// Insert key on arrow keypad + /// + DikInsert = 0xD2, + /// + /// Delete key on arrow keypad + /// + DikDelete = 0xD3, + /// + /// Left Windows key + /// + DikLwin = 0xDB, + /// + /// Right Windows key + /// + DikRwin = 0xDC, + /// + /// AppMenu key + /// + DikApps = 0xDD, + /// + /// System power key + /// + DikPower = 0xDE, + /// + /// System sleep key + /// + DikSleep = 0xDF, + /// + /// System wake key + /// + DikWake = 0xE3, + /// + /// Web search key + /// + DikWebsearch = 0xE5, + /// + /// Web favorites key + /// + DikWebfavorites = 0xE6, + /// + /// Web refresh key + /// + DikWebrefresh = 0xE7, + /// + /// Web stop key + /// + DikWebstop = 0xE8, + /// + /// Web forward key + /// + DikWebforward = 0xE9, + /// + /// Web back key + /// + DikWebback = 0xEA, + /// + /// My computer key + /// + DikMycomputer = 0xEB, + /// + /// Mail key + /// + DikMail = 0xEC, + /// + /// Media select + /// + DikMediaselect = 0xED, + /// + /// PageUp key on arrow keypad + /// + DikPageUp = DikPrior, + /// + /// PageDown key on arrow keypad + /// + DikPageDown = DikNext, + /// + /// Backspace key + /// + DikBackspace = DikBack, + /// + /// '*' key on numeric keypad + /// + DikNumpadStar = DikMultiply, + /// + /// Left alt key + /// + DikLalt = DikLmenu, + /// + /// Caps lock key + /// + DikCapslock = DikCapital, + /// + /// '-' key on numeric keypad + /// + DikNumpadMinus = DikSubtract, + /// + /// '+' key on numeric keypad + /// + DikNumpadPlus = DikAdd, + /// + /// '.' key on numeric keypad + /// + DikNumpadPeriod = DikDecimal, + /// + /// '/' key on numeric keypad + /// + DikNumpadSlash = DikDivide, + /// + /// Right alt key + /// + DikRalt = DikRmenu, + /// + /// Up arrow key on arrow keypad + /// + DikUparrow = DikUp, + /// + /// PageUp key on arrow keypad + /// + DikPgup = DikPrior, + /// + /// Left arrow key on arrow keypad + /// + DikLeftarrow = DikLeft, + /// + /// Right arrow key on arrow keypad + /// + DikRightarrow = DikRight, + /// + /// Down arrow key on arrow keypad + /// + DikDownarrow = DikDown, + /// + /// PageDown key on arrow keypad + /// + DikPgdn = DikNext, + + /// + /// + DikEnter = DikReturn, + /// + /// + DikNumpad_Equals = DikNumpadequals, + /// + /// + DikNumpad_Enter = DikNumpadenter, + /// + /// + DikNumpad_Comma = DikNumpadcomma, + + /// + /// + DikNumpad_Divide = DikNumpadSlash, + /// + /// + DikNumpadDivide = DikNumpadSlash, + /// + /// + DikNumpad_Multiply = DikNumpadStar, + /// + /// + DikNumpadMultiply = DikNumpadStar, + /// + /// + DikNumpad_Subtract = DikNumpadMinus, + /// + /// + DikNumpadSubtract = DikNumpadMinus, + /// + /// + DikNumpad_Decimal = DikNumpadPeriod, + /// + /// + DikNumpadDecimal = DikNumpadPeriod, + /// + /// + DikNumpad_Add = DikNumpadPlus, + /// + /// + DikNumpadAdd = DikNumpadPlus, + /// + /// + DikNumpad_7 = DikNumpad7, + /// + /// + DikNumpad_8 = DikNumpad8, + /// + /// + DikNumpad_9 = DikNumpad9, + /// + /// + DikNumpad_4 = DikNumpad4, + /// + /// + DikNumpad_5 = DikNumpad5, + /// + /// + DikNumpad_6 = DikNumpad6, + /// + /// + DikNumpad_1 = DikNumpad1, + /// + /// + DikNumpad_2 = DikNumpad2, + /// + /// + DikNumpad_3 = DikNumpad3, + /// + /// + DikNumpad_0 = DikNumpad0, + /// + /// + DikLeftBracket = DikLbracket, + /// + /// + DikRightBracket = DikRbracket, + + /// + /// + DikLeftAlt = DikLmenu, + /// + /// + DikRightAlt = DikRmenu, + /// + /// + DikRightControl = DikRcontrol, + /// + /// + DikLeftControl = DikLcontrol, + /// + /// + DikRightShift = DikRshift, + /// + /// + DikLeftShift = DikLshift + + + /* + //DikCircumflex = DikPrevtrack, + + Dikß = 0x0C, + Dikü = 0, + Dikö = 0, + Dikä = 0, + Diké = 0, + Dikè = 0, + Dikç = 0, + Dikà = 0, + Dikù = 0, + + DikAcute = 0, + DikCircumflex = 0, + DikPlus = 0, + DikHash = 0, + + DikSuperscriptTwo = 0, + DikAmpersand = 0, + DikDoubleQuote = 0, + DikLeftParenthesis = 0, + DikRightParenthesis = 0, + DikDollar = 0, + DikAsterisk = 0, + DikExclamationPoint = 0 + + DikScrollLock = 0x46, + DikABNT_C1 = 0x73, + DikABNT_C2 = 0x7E, + DikWebFavourites = 0, + DikGreenModifier = 0, + DikOrangeModifier = 0, + DikSection = 0, + DikClear = 0, + DikLeftBracket = 0, + DikRightBracket = 0, + DikUnderline = 0, + DikLessThan = 0, + DikGreaterThan = 0, + DikTilde = 0, + DikRing = 0, + DikUmlaut = 0, + DikHalf = 0, + DikDollar = 0, + DikSuperscriptTwo = 0, + DikAmpersand = 0, + DikDoubleQuote = 0, + DikLeftParenthesis = 0, + DikRightParenthesis = 0, + DikAsterisk = 0, + DikExclamationPoint = 0, + DikMacron = 0, + DikOverline = 0, + DikBreve = 0, + DikOverdot = 0, + DikHookAbove = 0, + DikRingAbove = 0, + DikDoubleAcute = 0, + DikCaron = 0, + DikVerticalLineAbove = 0, + DikDoubleVerticalLineAbove = 0, + DikDoubleGrave = 0, + DikCandrabindu = 0, + DikInvertedBreve = 0, + DikTurnedCommaAbove = 0, + DikCommaAbove = 0, + DikReversedCommaAbove = 0, + DikCommaAboveRight = 0, + DikGraveBelow = 0, + DikAcuteBelow = 0, + DikLeftTackBelow = 0, + DikRightTackBelow = 0, + DikLeftAngleAbove = 0, + DikHorn = 0, + DikLeftHalfRingBelow = 0, + DikUpTackBelow = 0, + DikDownTackBelow = 0, + DikPlusSignBelow = 0, + DikCedilla = 0*/ + + + + + + + + } +} \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput/Native/HARDWAREINPUT.cs b/InputSimulatorPlus/WindowsInput/Native/HARDWAREINPUT.cs new file mode 100644 index 0000000..de621d5 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/Native/HARDWAREINPUT.cs @@ -0,0 +1,28 @@ +using System; + +namespace WindowsInput.Native +{ +#pragma warning disable 649 + /// + /// 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) + /// Declared in Winuser.h, include Windows.h + /// + internal struct HARDWAREINPUT + { + /// + /// Value specifying the message generated by the input hardware. + /// + public UInt32 Msg; + + /// + /// Specifies the low-order word of the lParam parameter for uMsg. + /// + public UInt16 ParamL; + + /// + /// Specifies the high-order word of the lParam parameter for uMsg. + /// + public UInt16 ParamH; + } +#pragma warning restore 649 +} diff --git a/InputSimulatorPlus/WindowsInput/Native/INPUT.cs b/InputSimulatorPlus/WindowsInput/Native/INPUT.cs new file mode 100644 index 0000000..10ef88a --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/Native/INPUT.cs @@ -0,0 +1,30 @@ +using System; + +namespace WindowsInput.Native +{ +#pragma warning disable 649 + /// + /// 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) + /// Declared in Winuser.h, include Windows.h + /// + /// + /// This structure contains information identical to that used in the parameter list of the keybd_event or mouse_event function. + /// 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. + /// + internal struct INPUT + { + /// + /// Specifies the type of the input event. This member can be one of the following values. + /// - The event is a mouse event. Use the mi structure of the union. + /// - The event is a keyboard event. Use the ki structure of the union. + /// - Windows 95/98/Me: The event is from input hardware other than a keyboard or mouse. Use the hi structure of the union. + /// + public UInt32 Type; + + /// + /// The data structure that contains information about the simulated Mouse, Keyboard or Hardware event. + /// + public MOUSEKEYBDHARDWAREINPUT Data; + } +#pragma warning restore 649 +} diff --git a/InputSimulatorPlus/WindowsInput/Native/InputType.cs b/InputSimulatorPlus/WindowsInput/Native/InputType.cs new file mode 100644 index 0000000..231b362 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/Native/InputType.cs @@ -0,0 +1,23 @@ +namespace WindowsInput.Native +{ + /// + /// Specifies the type of the input event. This member can be one of the following values. + /// + internal enum InputType : uint // UInt32 + { + /// + /// INPUT_MOUSE = 0x00 (The event is a mouse event. Use the mi structure of the union.) + /// + Mouse = 0, + + /// + /// INPUT_KEYBOARD = 0x01 (The event is a keyboard event. Use the ki structure of the union.) + /// + Keyboard = 1, + + /// + /// 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.) + /// + Hardware = 2, + } +} diff --git a/InputSimulatorPlus/WindowsInput/Native/KEYBDINPUT.cs b/InputSimulatorPlus/WindowsInput/Native/KEYBDINPUT.cs new file mode 100644 index 0000000..03a4097 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/Native/KEYBDINPUT.cs @@ -0,0 +1,46 @@ +using System; + +namespace WindowsInput.Native +{ +#pragma warning disable 649 + /// + /// The KEYBDINPUT structure contains information about a simulated keyboard event. (see: http://msdn.microsoft.com/en-us/library/ms646271(VS.85).aspx) + /// Declared in Winuser.h, include Windows.h + /// + /// + /// 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. + /// 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. + /// + internal struct KEYBDINPUT + { + /// + /// 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. + /// + public UInt16 KeyCode; + + /// + /// 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. + /// + public UInt16 Scan; + + /// + /// Specifies various aspects of a keystroke. This member can be certain combinations of the following values. + /// KEYEVENTF_EXTENDEDKEY - If specified, the scan code was preceded by a prefix byte that has the value 0xE0 (224). + /// KEYEVENTF_KEYUP - If specified, the key is being released. If not specified, the key is being pressed. + /// KEYEVENTF_SCANCODE - If specified, wScan identifies the key and wVk is ignored. + /// 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. + /// + public UInt32 Flags; + + /// + /// Time stamp for the event, in milliseconds. If this parameter is zero, the system will provide its own time stamp. + /// + public UInt32 Time; + + /// + /// Specifies an additional value associated with the keystroke. Use the GetMessageExtraInfo function to obtain this information. + /// + public IntPtr ExtraInfo; + } +#pragma warning restore 649 +} diff --git a/InputSimulatorPlus/WindowsInput/Native/KeyboardFlag.cs b/InputSimulatorPlus/WindowsInput/Native/KeyboardFlag.cs new file mode 100644 index 0000000..f270788 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/Native/KeyboardFlag.cs @@ -0,0 +1,31 @@ +using System; + +namespace WindowsInput.Native +{ + /// + /// Specifies various aspects of a keystroke. This member can be certain combinations of the following values. + /// + [Flags] + internal enum KeyboardFlag : uint // UInt32 + { + /// + /// KEYEVENTF_EXTENDEDKEY = 0x0001 (If specified, the scan code was preceded by a prefix byte that has the value 0xE0 (224).) + /// + ExtendedKey = 0x0001, + + /// + /// KEYEVENTF_KEYUP = 0x0002 (If specified, the key is being released. If not specified, the key is being pressed.) + /// + KeyUp = 0x0002, + + /// + /// KEYEVENTF_UNICODE = 0x0004 (If specified, wScan identifies the key and wVk is ignored.) + /// + Unicode = 0x0004, + + /// + /// 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.) + /// + ScanCode = 0x0008, + } +} diff --git a/InputSimulatorPlus/WindowsInput/Native/MOUSEINPUT.cs b/InputSimulatorPlus/WindowsInput/Native/MOUSEINPUT.cs new file mode 100644 index 0000000..496ff0a --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/Native/MOUSEINPUT.cs @@ -0,0 +1,56 @@ +using System; + +namespace WindowsInput.Native +{ +#pragma warning disable 649 + /// + /// The MOUSEINPUT structure contains information about a simulated mouse event. (see: http://msdn.microsoft.com/en-us/library/ms646273(VS.85).aspx) + /// Declared in Winuser.h, include Windows.h + /// + /// + /// 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. + /// 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. + /// Windows 2000/XP: If MOUSEEVENTF_VIRTUALDESK is specified, the coordinates map to the entire virtual desktop. + /// 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). + /// 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. + /// 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. + /// + internal struct MOUSEINPUT + { + /// + /// 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. + /// + public Int32 X; + + /// + /// 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. + /// + public Int32 Y; + + /// + /// 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. + /// 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. + /// Windows 2000/XP: IfdwFlags does not contain MOUSEEVENTF_WHEEL, MOUSEEVENTF_XDOWN, or MOUSEEVENTF_XUP, then mouseData should be zero. + /// 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. + /// + public UInt32 MouseData; + + /// + /// 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. + /// 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. + /// 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. + /// + public UInt32 Flags; + + /// + /// Time stamp for the event, in milliseconds. If this parameter is 0, the system will provide its own time stamp. + /// + public UInt32 Time; + + /// + /// Specifies an additional value associated with the mouse event. An application calls GetMessageExtraInfo to obtain this extra information. + /// + public IntPtr ExtraInfo; + } +#pragma warning restore 649 +} \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput/Native/MOUSEKEYBDHARDWAREINPUT.cs b/InputSimulatorPlus/WindowsInput/Native/MOUSEKEYBDHARDWAREINPUT.cs new file mode 100644 index 0000000..0700f8e --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/Native/MOUSEKEYBDHARDWAREINPUT.cs @@ -0,0 +1,31 @@ +using System.Runtime.InteropServices; + +namespace WindowsInput.Native +{ +#pragma warning disable 649 + /// + /// 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) + /// + [StructLayout(LayoutKind.Explicit)] + internal struct MOUSEKEYBDHARDWAREINPUT + { + /// + /// The definition. + /// + [FieldOffset(0)] + public MOUSEINPUT Mouse; + + /// + /// The definition. + /// + [FieldOffset(0)] + public KEYBDINPUT Keyboard; + + /// + /// The definition. + /// + [FieldOffset(0)] + public HARDWAREINPUT Hardware; + } +#pragma warning restore 649 +} diff --git a/InputSimulatorPlus/WindowsInput/Native/MouseFlag.cs b/InputSimulatorPlus/WindowsInput/Native/MouseFlag.cs new file mode 100644 index 0000000..f86b1d1 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/Native/MouseFlag.cs @@ -0,0 +1,76 @@ +using System; + +namespace WindowsInput.Native +{ + /// + /// 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) + /// + [Flags] + internal enum MouseFlag : uint // UInt32 + { + /// + /// Specifies that movement occurred. + /// + Move = 0x0001, + + /// + /// Specifies that the left button was pressed. + /// + LeftDown = 0x0002, + + /// + /// Specifies that the left button was released. + /// + LeftUp = 0x0004, + + /// + /// Specifies that the right button was pressed. + /// + RightDown = 0x0008, + + /// + /// Specifies that the right button was released. + /// + RightUp = 0x0010, + + /// + /// Specifies that the middle button was pressed. + /// + MiddleDown = 0x0020, + + /// + /// Specifies that the middle button was released. + /// + MiddleUp = 0x0040, + + /// + /// Windows 2000/XP: Specifies that an X button was pressed. + /// + XDown = 0x0080, + + /// + /// Windows 2000/XP: Specifies that an X button was released. + /// + XUp = 0x0100, + + /// + /// Windows NT/2000/XP: Specifies that the wheel was moved, if the mouse has a wheel. The amount of movement is specified in mouseData. + /// + VerticalWheel = 0x0800, + + /// + /// 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. + /// + HorizontalWheel = 0x1000, + + /// + /// Windows 2000/XP: Maps coordinates to the entire desktop. Must be used with MOUSEEVENTF_ABSOLUTE. + /// + VirtualDesk = 0x4000, + + /// + /// 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. + /// + Absolute = 0x8000, + } +} diff --git a/InputSimulatorPlus/WindowsInput/Native/NativeMethods.cs b/InputSimulatorPlus/WindowsInput/Native/NativeMethods.cs new file mode 100644 index 0000000..2e84654 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/Native/NativeMethods.cs @@ -0,0 +1,158 @@ +using System; +using System.Runtime.InteropServices; + +namespace WindowsInput.Native +{ + /// + /// References all of the Native Windows API methods for the WindowsInput functionality. + /// + internal static class NativeMethods + { + /// + /// 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) + /// + /// 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. + /// + /// 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. + /// + /// Windows NT/2000/XP: The return value is zero for the following cases: + /// - The current desktop is not the active desktop + /// - The foreground thread belongs to another process and the desktop does not allow the hook or the journal record. + /// + /// 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. + /// + /// 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. + /// + /// + /// 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 + /// Copy CodeGetSystemMetrics(SM_SWAPBUTTON) which returns TRUE if the mouse buttons have been swapped. + /// + /// 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. + /// + /// 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. + /// + /// 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. + /// + /// Code Meaning + /// VK_LSHIFT Left-shift key. + /// VK_RSHIFT Right-shift key. + /// VK_LCONTROL Left-control key. + /// VK_RCONTROL Right-control key. + /// VK_LMENU Left-menu key. + /// VK_RMENU Right-menu key. + /// + /// These left- and right-distinguishing constants are only available when you call the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. + /// + [DllImport("user32.dll", SetLastError = true)] + public static extern Int16 GetAsyncKeyState(UInt16 virtualKeyCode); + + /// + /// 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) + /// + /// + /// 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. + /// 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. + /// + /// + /// The return value specifies the status of the specified virtual key, as follows: + /// If the high-order bit is 1, the key is down; otherwise, it is up. + /// 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. + /// + /// + /// 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. + /// 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. + /// To retrieve state information for all the virtual keys, use the GetKeyboardState function. + /// 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. + /// VK_LSHIFT + /// VK_RSHIFT + /// VK_LCONTROL + /// VK_RCONTROL + /// VK_LMENU + /// VK_RMENU + /// + /// These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. + /// + [DllImport("user32.dll", SetLastError = true)] + public static extern Int16 GetKeyState(UInt16 virtualKeyCode); + + /// + /// The SendInput function synthesizes keystrokes, mouse motions, and button clicks. + /// + /// Number of structures in the Inputs array. + /// Pointer to an array of INPUT structures. Each structure represents an event to be inserted into the keyboard or mouse input stream. + /// Specifies the size, in bytes, of an INPUT structure. If cbSize is not the size of an INPUT structure, the function fails. + /// 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. + /// + /// 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. + /// 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. + /// 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. + /// + [DllImport("user32.dll", SetLastError = true)] + public static extern UInt32 SendInput(UInt32 numberOfInputs, INPUT[] inputs, Int32 sizeOfInputStructure); + + /// + /// 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. + /// + /// + /// To set a thread's extra message information, use the SetMessageExtraInfo function. + [DllImport("user32.dll")] + public static extern IntPtr GetMessageExtraInfo(); + + /// + /// The MapVirtualKey function translates (maps) a virtual-key code into a scan + /// code or character value, or translates a scan code into a virtual-key code + /// + /// [in] Specifies the virtual-key code or scan code for a key. + /// How this value is interpreted depends on the value of the uMapType parameter + /// + /// [in] Specifies the translation to perform. The value of this + /// parameter depends on the value of the uCode parameter. + /// + /// Either a scan code, a virtual-key code, or a character value, depending on + /// the value of uCode and uMapType. If there is no translation, the return value is zero + /// + [DllImport("user32.dll")] + public static extern int MapVirtualKey(uint uCode, MapVirtualKeyMapTypes uMapType); + + /// + /// The set of valid MapTypes used in MapVirtualKey + /// + public enum MapVirtualKeyMapTypes : uint + { + /// + /// uCode is a virtual-key code and is translated into a scan code. + /// If it is a virtual-key code that does not distinguish between left- and + /// right-hand keys, the left-hand scan code is returned. + /// If there is no translation, the function returns 0. + /// + MapvkVkToVsc = 0x00, + + /// + /// uCode is a scan code and is translated into a virtual-key code that + /// does not distinguish between left- and right-hand keys. If there is no + /// translation, the function returns 0. + /// + MapvkVscToVk = 0x01, + + /// + /// uCode is a virtual-key code and is translated into an unshifted + /// character value in the low-order word of the return value. Dead keys (diacritics) + /// are indicated by setting the top bit of the return value. If there is no + /// translation, the function returns 0. + /// + MapvkVkToChar = 0x02, + + /// + /// Windows NT/2000/XP: uCode is a scan code and is translated into a + /// virtual-key code that distinguishes between left- and right-hand keys. If + /// there is no translation, the function returns 0. + /// + MapvkVscToVkEx = 0x03, + + /// + /// Not currently documented + /// + MapvkVkToVscEx = 0x04 + } + } +} \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput/Native/VirtualKeyCode.cs b/InputSimulatorPlus/WindowsInput/Native/VirtualKeyCode.cs new file mode 100644 index 0000000..8c35c62 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/Native/VirtualKeyCode.cs @@ -0,0 +1,960 @@ +using System; + +namespace WindowsInput.Native +{ + /// + /// The list of VirtualKeyCodes (see: http://msdn.microsoft.com/en-us/library/ms645540(VS.85).aspx) + /// + public enum VirtualKeyCode //: UInt16 + { + /// + /// Left mouse button + /// + LBUTTON = 0x01, + + /// + /// Right mouse button + /// + RBUTTON = 0x02, + + /// + /// Control-break processing + /// + CANCEL = 0x03, + + /// + /// Middle mouse button (three-button mouse) - NOT contiguous with LBUTTON and RBUTTON + /// + MBUTTON = 0x04, + + /// + /// Windows 2000/XP: X1 mouse button - NOT contiguous with LBUTTON and RBUTTON + /// + XBUTTON1 = 0x05, + + /// + /// Windows 2000/XP: X2 mouse button - NOT contiguous with LBUTTON and RBUTTON + /// + XBUTTON2 = 0x06, + + // 0x07 : Undefined + + /// + /// BACKSPACE key + /// + BACK = 0x08, + + /// + /// TAB key + /// + TAB = 0x09, + + // 0x0A - 0x0B : Reserved + + /// + /// CLEAR key + /// + CLEAR = 0x0C, + + /// + /// ENTER key + /// + RETURN = 0x0D, + + // 0x0E - 0x0F : Undefined + + /// + /// SHIFT key + /// + SHIFT = 0x10, + + /// + /// CTRL key + /// + CONTROL = 0x11, + + /// + /// ALT key + /// + MENU = 0x12, + + /// + /// PAUSE key + /// + PAUSE = 0x13, + + /// + /// CAPS LOCK key + /// + CAPITAL = 0x14, + + /// + /// Input Method Editor (IME) Kana mode + /// + KANA = 0x15, + + /// + /// IME Hanguel mode (maintained for compatibility; use HANGUL) + /// + HANGEUL = 0x15, + + /// + /// IME Hangul mode + /// + HANGUL = 0x15, + + // 0x16 : Undefined + + /// + /// IME Junja mode + /// + JUNJA = 0x17, + + /// + /// IME final mode + /// + FINAL = 0x18, + + /// + /// IME Hanja mode + /// + HANJA = 0x19, + + /// + /// IME Kanji mode + /// + KANJI = 0x19, + + // 0x1A : Undefined + + /// + /// ESC key + /// + ESCAPE = 0x1B, + + /// + /// IME convert + /// + CONVERT = 0x1C, + + /// + /// IME nonconvert + /// + NONCONVERT = 0x1D, + + /// + /// IME accept + /// + ACCEPT = 0x1E, + + /// + /// IME mode change request + /// + MODECHANGE = 0x1F, + + /// + /// SPACEBAR + /// + SPACE = 0x20, + + /// + /// PAGE UP key + /// + PRIOR = 0x21, + + /// + /// PAGE DOWN key + /// + NEXT = 0x22, + + /// + /// END key + /// + END = 0x23, + + /// + /// HOME key + /// + HOME = 0x24, + + /// + /// LEFT ARROW key + /// + LEFT = 0x25, + + /// + /// UP ARROW key + /// + UP = 0x26, + + /// + /// RIGHT ARROW key + /// + RIGHT = 0x27, + + /// + /// DOWN ARROW key + /// + DOWN = 0x28, + + /// + /// SELECT key + /// + SELECT = 0x29, + + /// + /// PRINT key + /// + PRINT = 0x2A, + + /// + /// EXECUTE key + /// + EXECUTE = 0x2B, + + /// + /// PRINT SCREEN key + /// + SNAPSHOT = 0x2C, + + /// + /// INS key + /// + INSERT = 0x2D, + + /// + /// DEL key + /// + DELETE = 0x2E, + + /// + /// HELP key + /// + HELP = 0x2F, + + /// + /// 0 key + /// + VK_0 = 0x30, + + /// + /// 1 key + /// + VK_1 = 0x31, + + /// + /// 2 key + /// + VK_2 = 0x32, + + /// + /// 3 key + /// + VK_3 = 0x33, + + /// + /// 4 key + /// + VK_4 = 0x34, + + /// + /// 5 key + /// + VK_5 = 0x35, + + /// + /// 6 key + /// + VK_6 = 0x36, + + /// + /// 7 key + /// + VK_7 = 0x37, + + /// + /// 8 key + /// + VK_8 = 0x38, + + /// + /// 9 key + /// + VK_9 = 0x39, + + // + // 0x3A - 0x40 : Udefined + // + + /// + /// A key + /// + VK_A = 0x41, + + /// + /// B key + /// + VK_B = 0x42, + + /// + /// C key + /// + VK_C = 0x43, + + /// + /// D key + /// + VK_D = 0x44, + + /// + /// E key + /// + VK_E = 0x45, + + /// + /// F key + /// + VK_F = 0x46, + + /// + /// G key + /// + VK_G = 0x47, + + /// + /// H key + /// + VK_H = 0x48, + + /// + /// I key + /// + VK_I = 0x49, + + /// + /// J key + /// + VK_J = 0x4A, + + /// + /// K key + /// + VK_K = 0x4B, + + /// + /// L key + /// + VK_L = 0x4C, + + /// + /// M key + /// + VK_M = 0x4D, + + /// + /// N key + /// + VK_N = 0x4E, + + /// + /// O key + /// + VK_O = 0x4F, + + /// + /// P key + /// + VK_P = 0x50, + + /// + /// Q key + /// + VK_Q = 0x51, + + /// + /// R key + /// + VK_R = 0x52, + + /// + /// S key + /// + VK_S = 0x53, + + /// + /// T key + /// + VK_T = 0x54, + + /// + /// U key + /// + VK_U = 0x55, + + /// + /// V key + /// + VK_V = 0x56, + + /// + /// W key + /// + VK_W = 0x57, + + /// + /// X key + /// + VK_X = 0x58, + + /// + /// Y key + /// + VK_Y = 0x59, + + /// + /// Z key + /// + VK_Z = 0x5A, + + /// + /// Left Windows key (Microsoft Natural keyboard) + /// + LWIN = 0x5B, + + /// + /// Right Windows key (Natural keyboard) + /// + RWIN = 0x5C, + + /// + /// Applications key (Natural keyboard) + /// + APPS = 0x5D, + + // 0x5E : reserved + + /// + /// Computer Sleep key + /// + SLEEP = 0x5F, + + /// + /// Numeric keypad 0 key + /// + NUMPAD0 = 0x60, + + /// + /// Numeric keypad 1 key + /// + NUMPAD1 = 0x61, + + /// + /// Numeric keypad 2 key + /// + NUMPAD2 = 0x62, + + /// + /// Numeric keypad 3 key + /// + NUMPAD3 = 0x63, + + /// + /// Numeric keypad 4 key + /// + NUMPAD4 = 0x64, + + /// + /// Numeric keypad 5 key + /// + NUMPAD5 = 0x65, + + /// + /// Numeric keypad 6 key + /// + NUMPAD6 = 0x66, + + /// + /// Numeric keypad 7 key + /// + NUMPAD7 = 0x67, + + /// + /// Numeric keypad 8 key + /// + NUMPAD8 = 0x68, + + /// + /// Numeric keypad 9 key + /// + NUMPAD9 = 0x69, + + /// + /// Multiply key + /// + MULTIPLY = 0x6A, + + /// + /// Add key + /// + ADD = 0x6B, + + /// + /// Separator key + /// + SEPARATOR = 0x6C, + + /// + /// Subtract key + /// + SUBTRACT = 0x6D, + + /// + /// Decimal key + /// + DECIMAL = 0x6E, + + /// + /// Divide key + /// + DIVIDE = 0x6F, + + /// + /// F1 key + /// + F1 = 0x70, + + /// + /// F2 key + /// + F2 = 0x71, + + /// + /// F3 key + /// + F3 = 0x72, + + /// + /// F4 key + /// + F4 = 0x73, + + /// + /// F5 key + /// + F5 = 0x74, + + /// + /// F6 key + /// + F6 = 0x75, + + /// + /// F7 key + /// + F7 = 0x76, + + /// + /// F8 key + /// + F8 = 0x77, + + /// + /// F9 key + /// + F9 = 0x78, + + /// + /// F10 key + /// + F10 = 0x79, + + /// + /// F11 key + /// + F11 = 0x7A, + + /// + /// F12 key + /// + F12 = 0x7B, + + /// + /// F13 key + /// + F13 = 0x7C, + + /// + /// F14 key + /// + F14 = 0x7D, + + /// + /// F15 key + /// + F15 = 0x7E, + + /// + /// F16 key + /// + F16 = 0x7F, + + /// + /// F17 key + /// + F17 = 0x80, + + /// + /// F18 key + /// + F18 = 0x81, + + /// + /// F19 key + /// + F19 = 0x82, + + /// + /// F20 key + /// + F20 = 0x83, + + /// + /// F21 key + /// + F21 = 0x84, + + /// + /// F22 key + /// + F22 = 0x85, + + /// + /// F23 key + /// + F23 = 0x86, + + /// + /// F24 key + /// + F24 = 0x87, + + // + // 0x88 - 0x8F : Unassigned + // + + /// + /// NUM LOCK key + /// + NUMLOCK = 0x90, + + /// + /// SCROLL LOCK key + /// + SCROLL = 0x91, + + // 0x92 - 0x96 : OEM Specific + + // 0x97 - 0x9F : Unassigned + + // + // L* & R* - left and right Alt, Ctrl and Shift virtual keys. + // Used only as parameters to GetAsyncKeyState() and GetKeyState(). + // No other API or message will distinguish left and right keys in this way. + // + + /// + /// Left SHIFT key - Used only as parameters to GetAsyncKeyState() and GetKeyState() + /// + LSHIFT = 0xA0, + + /// + /// Right SHIFT key - Used only as parameters to GetAsyncKeyState() and GetKeyState() + /// + RSHIFT = 0xA1, + + /// + /// Left CONTROL key - Used only as parameters to GetAsyncKeyState() and GetKeyState() + /// + LCONTROL = 0xA2, + + /// + /// Right CONTROL key - Used only as parameters to GetAsyncKeyState() and GetKeyState() + /// + RCONTROL = 0xA3, + + /// + /// Left MENU key - Used only as parameters to GetAsyncKeyState() and GetKeyState() + /// + LMENU = 0xA4, + + /// + /// Right MENU key - Used only as parameters to GetAsyncKeyState() and GetKeyState() + /// + RMENU = 0xA5, + + /// + /// Windows 2000/XP: Browser Back key + /// + BROWSER_BACK = 0xA6, + + /// + /// Windows 2000/XP: Browser Forward key + /// + BROWSER_FORWARD = 0xA7, + + /// + /// Windows 2000/XP: Browser Refresh key + /// + BROWSER_REFRESH = 0xA8, + + /// + /// Windows 2000/XP: Browser Stop key + /// + BROWSER_STOP = 0xA9, + + /// + /// Windows 2000/XP: Browser Search key + /// + BROWSER_SEARCH = 0xAA, + + /// + /// Windows 2000/XP: Browser Favorites key + /// + BROWSER_FAVORITES = 0xAB, + + /// + /// Windows 2000/XP: Browser Start and Home key + /// + BROWSER_HOME = 0xAC, + + /// + /// Windows 2000/XP: Volume Mute key + /// + VOLUME_MUTE = 0xAD, + + /// + /// Windows 2000/XP: Volume Down key + /// + VOLUME_DOWN = 0xAE, + + /// + /// Windows 2000/XP: Volume Up key + /// + VOLUME_UP = 0xAF, + + /// + /// Windows 2000/XP: Next Track key + /// + MEDIA_NEXT_TRACK = 0xB0, + + /// + /// Windows 2000/XP: Previous Track key + /// + MEDIA_PREV_TRACK = 0xB1, + + /// + /// Windows 2000/XP: Stop Media key + /// + MEDIA_STOP = 0xB2, + + /// + /// Windows 2000/XP: Play/Pause Media key + /// + MEDIA_PLAY_PAUSE = 0xB3, + + /// + /// Windows 2000/XP: Start Mail key + /// + LAUNCH_MAIL = 0xB4, + + /// + /// Windows 2000/XP: Select Media key + /// + LAUNCH_MEDIA_SELECT = 0xB5, + + /// + /// Windows 2000/XP: Start Application 1 key + /// + LAUNCH_APP1 = 0xB6, + + /// + /// Windows 2000/XP: Start Application 2 key + /// + LAUNCH_APP2 = 0xB7, + + // + // 0xB8 - 0xB9 : Reserved + // + + /// + /// Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ';:' key + /// + OEM_1 = 0xBA, + + /// + /// Windows 2000/XP: For any country/region, the '+' key + /// + OEM_PLUS = 0xBB, + + /// + /// Windows 2000/XP: For any country/region, the ',' key + /// + OEM_COMMA = 0xBC, + + /// + /// Windows 2000/XP: For any country/region, the '-' key + /// + OEM_MINUS = 0xBD, + + /// + /// Windows 2000/XP: For any country/region, the '.' key + /// + OEM_PERIOD = 0xBE, + + /// + /// Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '/?' key + /// + OEM_2 = 0xBF, + + /// + /// Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '`~' key + /// + OEM_3 = 0xC0, + + // + // 0xC1 - 0xD7 : Reserved + // + + // + // 0xD8 - 0xDA : Unassigned + // + + /// + /// Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '[{' key + /// + OEM_4 = 0xDB, + + /// + /// Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '\|' key + /// + OEM_5 = 0xDC, + + /// + /// Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ']}' key + /// + OEM_6 = 0xDD, + + /// + /// Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the 'single-quote/double-quote' key + /// + OEM_7 = 0xDE, + + /// + /// Used for miscellaneous characters; it can vary by keyboard. + /// + OEM_8 = 0xDF, + + // + // 0xE0 : Reserved + // + + // + // 0xE1 : OEM Specific + // + + /// + /// Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard + /// + OEM_102 = 0xE2, + + // + // (0xE3-E4) : OEM specific + // + + /// + /// Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key + /// + PROCESSKEY = 0xE5, + + // + // 0xE6 : OEM specific + // + + /// + /// 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 + /// + PACKET = 0xE7, + + // + // 0xE8 : Unassigned + // + + // + // 0xE9-F5 : OEM specific + // + + /// + /// Attn key + /// + ATTN = 0xF6, + + /// + /// CrSel key + /// + CRSEL = 0xF7, + + /// + /// ExSel key + /// + EXSEL = 0xF8, + + /// + /// Erase EOF key + /// + EREOF = 0xF9, + + /// + /// Play key + /// + PLAY = 0xFA, + + /// + /// Zoom key + /// + ZOOM = 0xFB, + + /// + /// Reserved + /// + NONAME = 0xFC, + + /// + /// PA1 key + /// + PA1 = 0xFD, + + /// + /// Clear key + /// + OEM_CLEAR = 0xFE, + } + + /// + /// Extension class for VirtualKeyCode + /// + public static class VKExtend + { + /// + /// Returns the equivalent virtualkey for an input character + /// + /// + /// Character to input + /// + public static VirtualKeyCode FromChar(this VirtualKeyCode VK, char InputChar) + { + InputChar = Convert.ToChar(InputChar.ToString().ToUpper()); + int code = (byte)InputChar; + return (VirtualKeyCode)code; + } + } +} diff --git a/InputSimulatorPlus/WindowsInput/Native/XButton.cs b/InputSimulatorPlus/WindowsInput/Native/XButton.cs new file mode 100644 index 0000000..5b61024 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/Native/XButton.cs @@ -0,0 +1,18 @@ +namespace WindowsInput.Native +{ + /// + /// XButton definitions for use in the MouseData property of the structure. (See: http://msdn.microsoft.com/en-us/library/ms646273(VS.85).aspx) + /// + internal enum XButton : uint + { + /// + /// Set if the first X button is pressed or released. + /// + XButton1 = 0x0001, + + /// + /// Set if the second X button is pressed or released. + /// + XButton2 = 0x0002, + } +} diff --git a/InputSimulatorPlus/WindowsInput/Properties/AssemblyInfo.cs b/InputSimulatorPlus/WindowsInput/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..73f8db8 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/Properties/AssemblyInfo.cs @@ -0,0 +1,38 @@ +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("WindowsInputPlus")] +[assembly: AssemblyDescription("Fork of the original Windows Input Simulator with scan code support for increased compatibility.")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Theodoros Chatzigiannakis")] +[assembly: AssemblyProduct("WindowsInputPlus")] +[assembly: AssemblyCopyright("Copyright © michaelnoonan 2010, Copyright © Theodoros Chatzigiannakis 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: CLSCompliant(true)] +[assembly: InternalsVisibleTo("WindowsInput.Tests,PublicKey=00240000048000009400000006020000002400005253413100040000010001004d0fe1ddb5b46f75b2d00740763ead8fd41e4212ca347163134409b7e9e99c80f3eef5772166a965ecd31bea7c7d68c2356f49db0ebec721cf1bad6f71f63092d90e22eccb84c374b0ae91553c6e74a8dbfa36f34520993ec0a1780df0852e698a803dd155b83a070f21057417dbd7128e70b21ad5c5626b51a4f18dd70351b8")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("a04b3cc4-a36c-4597-b0a9-d6f16dd6dcf6")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.7.0")] \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput/WindowsInput.csproj b/InputSimulatorPlus/WindowsInput/WindowsInput.csproj new file mode 100644 index 0000000..9fab198 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/WindowsInput.csproj @@ -0,0 +1,95 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {3549CD6F-80F8-450F-B99E-CF0A736B1F2A} + Library + Properties + WindowsInput + WindowsInput + v4.7.2 + 512 + + + + + 3.5 + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + bin\Debug\WindowsInput.xml + true + AllRules.ruleset + false + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + bin\Release\WindowsInput.xml + AllRules.ruleset + false + + + true + + + WindowsInput.snk + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput/WindowsInput.nuspec b/InputSimulatorPlus/WindowsInput/WindowsInput.nuspec new file mode 100644 index 0000000..91955d0 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/WindowsInput.nuspec @@ -0,0 +1,19 @@ + + + + InputSimulatorPlus + 1.0.7.0 + Windows Input Simulator Plus + Michael Noonan, Theodoros Chatzigiannakis + TChatzigiannakis + false + https://github.com/TChatzigiannakis/InputSimulatorPlus + This package is a fork of the Windows Input Simulator package. If you have encountered applications that do not receive input from the original Windows Input Simulator, try replacing it with this package instead. + + Copyright 2009-2018 + c# windows input + + + + + \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput/WindowsInput.snk b/InputSimulatorPlus/WindowsInput/WindowsInput.snk new file mode 100644 index 0000000..5104dcc Binary files /dev/null and b/InputSimulatorPlus/WindowsInput/WindowsInput.snk differ diff --git a/InputSimulatorPlus/WindowsInput/WindowsInputDeviceStateAdaptor.cs b/InputSimulatorPlus/WindowsInput/WindowsInputDeviceStateAdaptor.cs new file mode 100644 index 0000000..4a43f70 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/WindowsInputDeviceStateAdaptor.cs @@ -0,0 +1,157 @@ +using System; +using WindowsInput.Native; + +namespace WindowsInput +{ + /// + /// An implementation of for Windows by calling the native and methods. + /// + public class WindowsInputDeviceStateAdaptor : IInputDeviceStateAdaptor + { + + /// + /// 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) + /// + /// The for the key. + /// + /// true if the key is down; otherwise, false. + /// + /// + /// 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. + /// 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. + /// To retrieve state information for all the virtual keys, use the GetKeyboardState function. + /// 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. + /// VK_LSHIFT + /// VK_RSHIFT + /// VK_LCONTROL + /// VK_RCONTROL + /// VK_LMENU + /// VK_RMENU + /// + /// These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. + /// + public bool IsKeyDown(VirtualKeyCode keyCode) + { + Int16 result = NativeMethods.GetKeyState((UInt16)keyCode); + return (result < 0); + } + + /// + /// Determines whether the specified key is up or downby calling the function. (See: http://msdn.microsoft.com/en-us/library/ms646301(VS.85).aspx) + /// + /// The for the key. + /// + /// true if the key is up; otherwise, false. + /// + /// + /// 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. + /// 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. + /// To retrieve state information for all the virtual keys, use the GetKeyboardState function. + /// 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. + /// VK_LSHIFT + /// VK_RSHIFT + /// VK_LCONTROL + /// VK_RCONTROL + /// VK_LMENU + /// VK_RMENU + /// + /// These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. + /// + public bool IsKeyUp(VirtualKeyCode keyCode) + { + return !IsKeyDown(keyCode); + } + + /// + /// 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) + /// + /// The for the key. + /// + /// true if the key is down; otherwise, false. + /// + /// + /// 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 + /// Copy CodeGetSystemMetrics(SM_SWAPBUTTON) which returns TRUE if the mouse buttons have been swapped. + /// + /// 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. + /// + /// 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. + /// + /// 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. + /// + /// Code Meaning + /// VK_LSHIFT Left-shift key. + /// VK_RSHIFT Right-shift key. + /// VK_LCONTROL Left-control key. + /// VK_RCONTROL Right-control key. + /// VK_LMENU Left-menu key. + /// VK_RMENU Right-menu key. + /// + /// These left- and right-distinguishing constants are only available when you call the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. + /// + public bool IsHardwareKeyDown(VirtualKeyCode keyCode) + { + var result = NativeMethods.GetAsyncKeyState((UInt16)keyCode); + return (result < 0); + } + + /// + /// 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) + /// + /// The for the key. + /// + /// true if the key is up; otherwise, false. + /// + /// + /// 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 + /// Copy CodeGetSystemMetrics(SM_SWAPBUTTON) which returns TRUE if the mouse buttons have been swapped. + /// + /// 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. + /// + /// 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. + /// + /// 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. + /// + /// Code Meaning + /// VK_LSHIFT Left-shift key. + /// VK_RSHIFT Right-shift key. + /// VK_LCONTROL Left-control key. + /// VK_RCONTROL Right-control key. + /// VK_LMENU Left-menu key. + /// VK_RMENU Right-menu key. + /// + /// These left- and right-distinguishing constants are only available when you call the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. + /// + public bool IsHardwareKeyUp(VirtualKeyCode keyCode) + { + return !IsHardwareKeyDown(keyCode); + } + + /// + /// 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) + /// + /// The for the key. + /// + /// true if the toggling key is toggled on (in-effect); otherwise, false. + /// + /// + /// 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. + /// 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. + /// To retrieve state information for all the virtual keys, use the GetKeyboardState function. + /// 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. + /// VK_LSHIFT + /// VK_RSHIFT + /// VK_LCONTROL + /// VK_RCONTROL + /// VK_LMENU + /// VK_RMENU + /// + /// These left- and right-distinguishing constants are available to an application only through the GetKeyboardState, SetKeyboardState, GetAsyncKeyState, GetKeyState, and MapVirtualKey functions. + /// + public bool IsTogglingKeyInEffect(VirtualKeyCode keyCode) + { + Int16 result = NativeMethods.GetKeyState((UInt16)keyCode); + return (result & 0x01) == 0x01; + } + } +} \ No newline at end of file diff --git a/InputSimulatorPlus/WindowsInput/WindowsInputMessageDispatcher.cs b/InputSimulatorPlus/WindowsInput/WindowsInputMessageDispatcher.cs new file mode 100644 index 0000000..d978152 --- /dev/null +++ b/InputSimulatorPlus/WindowsInput/WindowsInputMessageDispatcher.cs @@ -0,0 +1,28 @@ +using System; +using System.Runtime.InteropServices; +using WindowsInput.Native; + +namespace WindowsInput +{ + /// + /// Implements the by calling SendInput. + /// + internal class WindowsInputMessageDispatcher : IInputMessageDispatcher + { + /// + /// Dispatches the specified list of messages in their specified order by issuing a single called to SendInput. + /// + /// The list of messages to be dispatched. + /// If the array is empty. + /// If the array is null. + /// If the any of the commands in the array could not be sent successfully. + public void DispatchInput(INPUT[] inputs) + { + if (inputs == null) throw new ArgumentNullException("inputs"); + if (inputs.Length == 0) throw new ArgumentException("The input array was empty", "inputs"); + var successful = NativeMethods.SendInput((UInt32)inputs.Length, inputs, Marshal.SizeOf(typeof (INPUT))); + if (successful != inputs.Length) + 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."); + } + } +} \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..985ff02 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 mhwlng + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..1598113 --- /dev/null +++ b/README.md @@ -0,0 +1,104 @@ +# streamdeck-starcitizen + +**WORK IN PROGRESS** + +TODO : + +* Test multiple language keyboards (only lightly tested 3.13 with US keyboard) + +* Automatically update binding in streamdeck plugin when changing binding in Star Citizen options screen (now streamdeck.exe has to be restarted) + +* Add more logging to pluginlog.log + +* Allow switching between LIVE and PTU versions. (Currently gets binding only from LIVE installation) + +**Elgato Stream Deck button plugin for Star Citizen** + +This plugin connects to Star Citizen to get the key bindings. + +Credit goes to https://github.com/SCToolsfactory/SCJMapper-V2 for all the code to get the defaultProfile.xml from the pk4 file etc. + +The button works in a similar way, to the streamdeck 'Hotkey' button type. +So, there is only one image and there is no game state feedback for these buttons. +The differences with the 'Hotkey' buttons are, that it gets the keyboard binding from the game. +When the stream deck button is pushed, the 'key down' event is sent to the keyboard +and only after the stream deck button is released, the 'key up' event is sent to the keyboard. + +A sound can be played when pressing a button. + +**You can clear the sound path, by clicking on the label in front of the file picker edit box.** + +The buttons can also be used with multi-action buttons. + +After you install the plugin in the streamdeck software, then there will be a new button type in the streamdeck software. + +Choose a button in the streamdeck software (drag and drop), then choose a Star Citizen function for that button (that must have a keyboard binding in Star Citizen!) and then choose any picture for that button. + +Add an image to a button in this way: + +![Button Image](https://i.imgur.com/xkgy7uZ.png) +Animated gif files are supported. + + +When the plugin is first started, it finds and opens the game file : + +`C:\Program Files\Roberts Space Industries\StarCitizen\LIVE\Data.p4k` + +and extracts `defaultProfile.xml` and also english text resources. This could take more than 10 seconds. + +Compressed versions (files ending in .scj) are cached in the plugin directory and should be automatically refreshed, the next time Star Citizen is updated to a new version. + +You can also delete the .scj files and restart the plugin, to extract the files from the p4k file again. + +For easier debugging, installation and testing, `defaultProfile.xml`, `dropdowntemplate.html` and `keybindings.csv` files are created in the plugin directory. + +The plugin uses all the active keyboard bindings from `defaultProfile.xml` and then overrules some of the bindings, with any custom keyboard bindings from this file : + +`C:\Program Files\Roberts Space Industries\StarCitizen\LIVE\USER\Client\0\Profiles\default\actionmaps.xml` + +The `dropdowntemplate.html` can be used to update the `%appdata%\Elgato\StreamDeck\Plugins\com.mhwlng.starcitizen.sdPlugin\PropertyInspector\StarCitizen\Static.html` file. + + + +The plugin installer is here: https://github.com/mhwlng/streamdeck-starcitizen/releases + +To install the plugin, double click the file `com.mhwlng.starcitizen.streamDeckPlugin` which should install the plugin. + +(This only works, if the plugin not already installed. Otherwise you will need to uninstall or remove the plugin first.) + +This .streamDeckPlugin file is a zip file and the contents are simply copied to : + +`%appdata%\Elgato\StreamDeck\Plugins\com.mhwlng.starcitizen.sdPlugin` + +To update to a new version : + +Stop the Stream Deck application: + +`c:\Program Files\Elgato\StreamDeck\StreamDeck.exe` + +Then delete the `%appdata%\Elgato\StreamDeck\Plugins\com.mhwlng.starcitizen.sdPlugin` directory. (make a backup copy first) + +Then start the streamdeck software again. + +Then double click the file `com.mhwlng.starcitizen.streamDeckPlugin` as usual. + +MAKE SURE that you save any images, profiles etc. that you put in these directories yourself, BEFORE deleting the directory. +And put them back after the installation. +The plugin installer doesn't come with button images. + +The button configurations are not stored in the plugin directory. + +After uninstalling and re-installing the plugin, all the button definition should still be there. + +The com.mhwlng.starcitizen.sdPlugin directory contains a pluginlog.log file, which may be useful for troubleshooting. + +Thanks to : + +https://github.com/BarRaider/streamdeck-tools + +https://github.com/SCToolsfactory/SCJMapper-V2 + +https://github.com/ishaaniMittal/inputsimulator + +https://nerdordie.com/product/stream-deck-key-icons/ + diff --git a/starcitizen.sln b/starcitizen.sln new file mode 100644 index 0000000..1d0a0d0 --- /dev/null +++ b/starcitizen.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31515.178 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "starcitizen", "starcitizen\starcitizen.csproj", "{761FCC88-EAF9-4C7A-BBFD-139D186437A5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsInput", "InputSimulatorPlus\WindowsInput\WindowsInput.csproj", "{3549CD6F-80F8-450F-B99E-CF0A736B1F2A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {761FCC88-EAF9-4C7A-BBFD-139D186437A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {761FCC88-EAF9-4C7A-BBFD-139D186437A5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {761FCC88-EAF9-4C7A-BBFD-139D186437A5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {761FCC88-EAF9-4C7A-BBFD-139D186437A5}.Release|Any CPU.Build.0 = Release|Any CPU + {3549CD6F-80F8-450F-B99E-CF0A736B1F2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3549CD6F-80F8-450F-B99E-CF0A736B1F2A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3549CD6F-80F8-450F-B99E-CF0A736B1F2A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3549CD6F-80F8-450F-B99E-CF0A736B1F2A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D814FC9C-53B9-4CB1-B46E-AF2604D640B2} + EndGlobalSection +EndGlobal diff --git a/starcitizen/App.config b/starcitizen/App.config new file mode 100644 index 0000000..a68f059 --- /dev/null +++ b/starcitizen/App.config @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/starcitizen/Audio/AudioPlaybackEngine .cs b/starcitizen/Audio/AudioPlaybackEngine .cs new file mode 100644 index 0000000..818617c --- /dev/null +++ b/starcitizen/Audio/AudioPlaybackEngine .cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NAudio.Wave; +using NAudio.Wave.SampleProviders; + +namespace starcitizen +{ + class AudioPlaybackEngine : IDisposable + { + private readonly IWavePlayer outputDevice; + private readonly MixingSampleProvider mixer; + + public AudioPlaybackEngine(int sampleRate = 44100, int channelCount = 2) + { + outputDevice = new WaveOutEvent(); + mixer = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, channelCount)); + mixer.ReadFully = true; + outputDevice.Init(mixer); + outputDevice.Play(); + } + + public void PlaySound(string fileName) + { + var input = new AudioFileReader(fileName); + AddMixerInput(new AutoDisposeFileReader(input)); + } + + private ISampleProvider ConvertToRightChannelCount(ISampleProvider input) + { + if (input.WaveFormat.Channels == mixer.WaveFormat.Channels) + { + return input; + } + if (input.WaveFormat.Channels == 1 && mixer.WaveFormat.Channels == 2) + { + return new MonoToStereoSampleProvider(input); + } + throw new NotImplementedException("Not yet implemented this channel count conversion"); + } + + public void PlaySound(CachedSound sound) + { + AddMixerInput(new CachedSoundSampleProvider(sound)); + } + + private void AddMixerInput(ISampleProvider input) + { + mixer.AddMixerInput(ConvertToRightChannelCount(input)); + } + + public void Dispose() + { + outputDevice.Dispose(); + } + + public static readonly AudioPlaybackEngine Instance = new AudioPlaybackEngine(44100, 2); + } +} diff --git a/starcitizen/Audio/AutoDisposeFileReader.cs b/starcitizen/Audio/AutoDisposeFileReader.cs new file mode 100644 index 0000000..4046888 --- /dev/null +++ b/starcitizen/Audio/AutoDisposeFileReader.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NAudio.Wave; + +namespace starcitizen +{ + class AutoDisposeFileReader : ISampleProvider + { + private readonly AudioFileReader reader; + private bool isDisposed; + public AutoDisposeFileReader(AudioFileReader reader) + { + this.reader = reader; + this.WaveFormat = reader.WaveFormat; + } + + public int Read(float[] buffer, int offset, int count) + { + if (isDisposed) + return 0; + int read = reader.Read(buffer, offset, count); + if (read == 0) + { + reader.Dispose(); + isDisposed = true; + } + return read; + } + + public WaveFormat WaveFormat { get; private set; } + } +} diff --git a/starcitizen/Audio/CachedSound.cs b/starcitizen/Audio/CachedSound.cs new file mode 100644 index 0000000..a77a19a --- /dev/null +++ b/starcitizen/Audio/CachedSound.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NAudio.Wave; + +namespace starcitizen +{ + class CachedSound + { + public float[] AudioData { get; private set; } + public WaveFormat WaveFormat { get; private set; } + public CachedSound(string audioFileName) + { + using (var audioFileReader = new AudioFileReader(audioFileName)) + { + // TODO: could add resampling in here if required + WaveFormat = audioFileReader.WaveFormat; + var wholeFile = new List((int)(audioFileReader.Length / 4)); + var readBuffer = new float[audioFileReader.WaveFormat.SampleRate * audioFileReader.WaveFormat.Channels]; + int samplesRead; + while ((samplesRead = audioFileReader.Read(readBuffer, 0, readBuffer.Length)) > 0) + { + wholeFile.AddRange(readBuffer.Take(samplesRead)); + } + AudioData = wholeFile.ToArray(); + } + } + } +} diff --git a/starcitizen/Audio/CachedSoundSampleProvider.cs b/starcitizen/Audio/CachedSoundSampleProvider.cs new file mode 100644 index 0000000..092150f --- /dev/null +++ b/starcitizen/Audio/CachedSoundSampleProvider.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NAudio.Wave; + +namespace starcitizen +{ + class CachedSoundSampleProvider : ISampleProvider + { + private readonly CachedSound cachedSound; + private long position; + + public CachedSoundSampleProvider(CachedSound cachedSound) + { + this.cachedSound = cachedSound; + } + + public int Read(float[] buffer, int offset, int count) + { + var availableSamples = cachedSound.AudioData.Length - position; + var samplesToCopy = Math.Min(availableSamples, count); + Array.Copy(cachedSound.AudioData, position, buffer, offset, samplesToCopy); + position += samplesToCopy; + return (int)samplesToCopy; + } + + public WaveFormat WaveFormat { get { return cachedSound.WaveFormat; } } + } +} diff --git a/starcitizen/Buttons/StarCitizenBase.cs b/starcitizen/Buttons/StarCitizenBase.cs new file mode 100644 index 0000000..d7322c5 --- /dev/null +++ b/starcitizen/Buttons/StarCitizenBase.cs @@ -0,0 +1,149 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; +using WindowsInput; +using WindowsInput.Native; +using BarRaider.SdTools; + +namespace starcitizen.Buttons +{ + public abstract class StarCitizenBase : PluginBase + { + [DllImport("user32.dll")] + private static extern uint MapVirtualKeyEx(uint uCode, uint uMapType, IntPtr dwhkl); + + [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] + private static extern IntPtr GetForegroundWindow(); + + [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] + private static extern int GetWindowThreadProcessId(IntPtr handleWindow, out int lpdwProcessID); + + [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] + private static extern IntPtr GetKeyboardLayout(int WindowsThreadProcessID); + + private static Dictionary _lastStatus = new Dictionary(); + + protected bool InputRunning; + protected bool ForceStop = false; + protected StarCitizenBase(SDConnection connection, InitialPayload payload) : base(connection, payload) + { + //Logger.Instance.LogMessage(TracingLevel.INFO, "aa"); + } + + public override void Dispose() + { + //Logger.Instance.LogMessage(TracingLevel.INFO, "bb"); + } + + public override void KeyReleased(KeyPayload payload) { } + + + public override void OnTick() + { + //Logger.Instance.LogMessage(TracingLevel.INFO, "dd"); + + //var deviceInfo = Connection.DeviceInfo(); + + } + + public override void ReceivedGlobalSettings(ReceivedGlobalSettingsPayload payload) { } + + private void SendInputDown(string inputText) + { + var text = inputText; + + for (var idx = 0; idx < text.Length && !ForceStop; idx++) + { + var macro = CommandTools.ExtractMacro(text, idx); + idx += macro.Length - 1; + macro = macro.Substring(1, macro.Length - 2); + + HandleMacroDown(macro); + } + } + + private void SendInputUp(string inputText) + { + var text = inputText; + + for (var idx = 0; idx < text.Length && !ForceStop; idx++) + { + var macro = CommandTools.ExtractMacro(text, idx); + idx += macro.Length - 1; + macro = macro.Substring(1, macro.Length - 2); + + HandleMacroUp(macro); + } + } + + private void HandleMacroDown(string macro) + { + var keyStrokes = CommandTools.ExtractKeyStrokes(macro); + + // Actually initiate the keystrokes + if (keyStrokes.Count > 0) + { + var iis = new InputSimulator(); + var keyCode = keyStrokes.Last(); + keyStrokes.Remove(keyCode); + + if (keyStrokes.Count > 0) + { + iis.Keyboard.DelayedModifiedKeyStrokeDown(keyStrokes.Select(ks => ks), keyCode, 40); + + } + else // Single Keycode + { + iis.Keyboard.DelayedKeyPressDown(keyCode, 40); + } + } + } + + + private void HandleMacroUp(string macro) + { + var keyStrokes = CommandTools.ExtractKeyStrokes(macro); + + // Actually initiate the keystrokes + if (keyStrokes.Count > 0) + { + var iis = new InputSimulator(); + var keyCode = keyStrokes.Last(); + keyStrokes.Remove(keyCode); + + if (keyStrokes.Count > 0) + { + iis.Keyboard.DelayedModifiedKeyStrokeUp(keyStrokes.Select(ks => ks), keyCode, 40); + + } + else // Single Keycode + { + iis.Keyboard.DelayedKeyPressUp(keyCode, 40); + } + } + } + + protected void SendKeypressDown(string keyInfo) + { + if (!string.IsNullOrEmpty(keyInfo)) + { + SendInputDown("{" + keyInfo + "}"); + } + } + + + protected void SendKeypressUp(string keyInfo) + { + if (!string.IsNullOrEmpty(keyInfo)) + { + SendInputUp("{" + keyInfo + "}"); + } + } + + + + } +} diff --git a/starcitizen/Buttons/Static.cs b/starcitizen/Buttons/Static.cs new file mode 100644 index 0000000..ef6a241 --- /dev/null +++ b/starcitizen/Buttons/Static.cs @@ -0,0 +1,157 @@ +using System; +using System.IO; +using System.Threading.Tasks; +using System.Windows.Input; +using WindowsInput.Native; +using BarRaider.SdTools; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +// ReSharper disable StringLiteralTypo + +namespace starcitizen.Buttons +{ + + [PluginActionId("com.mhwlng.starcitizen.static")] + public class Static : StarCitizenBase + { + protected class PluginSettings + { + public static PluginSettings CreateDefaultSettings() + { + var instance = new PluginSettings + { + Function = string.Empty, + }; + + return instance; + } + + [JsonProperty(PropertyName = "function")] + public string Function { get; set; } + + [FilenameProperty] + [JsonProperty(PropertyName = "clickSound")] + public string ClickSoundFilename { get; set; } + + } + + + PluginSettings settings; + private CachedSound _clickSound = null; + + + public Static(SDConnection connection, InitialPayload payload) : base(connection, payload) + { + if (payload.Settings == null || payload.Settings.Count == 0) + { + //Logger.Instance.LogMessage(TracingLevel.DEBUG, "Repeating Static Constructor #1"); + + settings = PluginSettings.CreateDefaultSettings(); + Connection.SetSettingsAsync(JObject.FromObject(settings)).Wait(); + + } + else + { + //Logger.Instance.LogMessage(TracingLevel.DEBUG, "Repeating Static Constructor #2"); + + settings = payload.Settings.ToObject(); + HandleFileNames(); + } + + } + + + public override void KeyPressed(KeyPayload payload) + { + if (InputRunning || Program.dpReader == null) + { + ForceStop = true; + return; + } + + ForceStop = false; + + var action = Program.dpReader.GetBinding(settings.Function); + if (action != null) + { + Logger.Instance.LogMessage(TracingLevel.INFO, CommandTools.ConvertKeyString(action.Keyboard)); + + SendKeypressDown(CommandTools.ConvertKeyString(action.Keyboard)); + } + + if (_clickSound != null) + { + try + { + AudioPlaybackEngine.Instance.PlaySound(_clickSound); + } + catch (Exception ex) + { + Logger.Instance.LogMessage(TracingLevel.FATAL, $"PlaySound: {ex}"); + } + + } + + } + + public override void KeyReleased(KeyPayload payload) + { + + if (InputRunning || Program.dpReader == null) + { + ForceStop = true; + return; + } + + ForceStop = false; + + var action = Program.dpReader.GetBinding(settings.Function); + if (action != null) + { + Logger.Instance.LogMessage(TracingLevel.INFO, CommandTools.ConvertKeyString(action.Keyboard)); + + SendKeypressUp(CommandTools.ConvertKeyString(action.Keyboard)); + } + + } + + public override void Dispose() + { + base.Dispose(); + + //Logger.Instance.LogMessage(TracingLevel.DEBUG, "Destructor called #1"); + } + + + public override void ReceivedSettings(ReceivedSettingsPayload payload) + { + //Logger.Instance.LogMessage(TracingLevel.DEBUG, "ReceivedSettings"); + + // New in StreamDeck-Tools v2.0: + BarRaider.SdTools.Tools.AutoPopulateSettings(settings, payload.Settings); + HandleFileNames(); + } + + private void HandleFileNames() + { + _clickSound = null; + if (File.Exists(settings.ClickSoundFilename)) + { + try + { + _clickSound = new CachedSound(settings.ClickSoundFilename); + } + catch (Exception ex) + { + Logger.Instance.LogMessage(TracingLevel.FATAL, $"CachedSound: {settings.ClickSoundFilename} {ex}"); + + _clickSound = null; + settings.ClickSoundFilename = null; + } + } + + Connection.SetSettingsAsync(JObject.FromObject(settings)).Wait(); + } + } +} diff --git a/starcitizen/CommandTools.cs b/starcitizen/CommandTools.cs new file mode 100644 index 0000000..5c868c0 --- /dev/null +++ b/starcitizen/CommandTools.cs @@ -0,0 +1,189 @@ +using BarRaider.SdTools; +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using WindowsInput.Native; + +namespace starcitizen +{ + internal static class CommandTools + { + internal const char MACRO_START_CHAR = '{'; + internal const string MACRO_END = "}}"; + internal const string REGEX_MACRO = @"^\{(\{[^\{\}]+\})+\}$"; + internal const string REGEX_SUB_COMMAND = @"(\{[^\{\}]+\})"; + + public static string ConvertKeyString(string keyboard) + { + var keys = keyboard.Split('+'); + keyboard = ""; + foreach (var key in keys) + { + keyboard += "{" + FromSCKeyboardCmd(key) + "}"; + } + + return keyboard; + } + + private static DirectInputKeyCode FromSCKeyboardCmd(string scKey) + { + switch (scKey) + { + // handle modifiers first + case "lalt": return DirectInputKeyCode.DikLmenu; + case "ralt": return DirectInputKeyCode.DikRmenu; + case "lshift": return DirectInputKeyCode.DikLeftShift; + case "rshift": return DirectInputKeyCode.DikRightShift; + case "lctrl": return DirectInputKeyCode.DikLeftControl; + case "rctrl": return DirectInputKeyCode.DikRightControl; + + // function keys first + case "f1": return DirectInputKeyCode.DikF1; + case "f2": return DirectInputKeyCode.DikF2; + case "f3": return DirectInputKeyCode.DikF3; + case "f4": return DirectInputKeyCode.DikF4; + case "f5": return DirectInputKeyCode.DikF5; + case "f6": return DirectInputKeyCode.DikF6; + case "f7": return DirectInputKeyCode.DikF7; + case "f8": return DirectInputKeyCode.DikF8; + case "f9": return DirectInputKeyCode.DikF9; + case "f10": return DirectInputKeyCode.DikF10; + case "f11": return DirectInputKeyCode.DikF11; + case "f12": return DirectInputKeyCode.DikF12; + case "f13": return DirectInputKeyCode.DikF13; + case "f14": return DirectInputKeyCode.DikF14; + case "f15": return DirectInputKeyCode.DikF15; + + // all keys where the DX name does not match the SC name + // Numpad + case "numlock": return DirectInputKeyCode.DikNumlock; + + case "np_divide": return DirectInputKeyCode.DikDivide; + case "np_multiply": return DirectInputKeyCode.DikMultiply; + case "np_subtract": return DirectInputKeyCode.DikSubtract; + case "np_add": return DirectInputKeyCode.DikAdd; + case "np_period": return DirectInputKeyCode.DikDecimal; + case "np_enter": return DirectInputKeyCode.DikNumpadenter; + case "np_0": return DirectInputKeyCode.DikNumpad0; + case "np_1": return DirectInputKeyCode.DikNumpad1; + case "np_2": return DirectInputKeyCode.DikNumpad2; + case "np_3": return DirectInputKeyCode.DikNumpad3; + case "np_4": return DirectInputKeyCode.DikNumpad4; + case "np_5": return DirectInputKeyCode.DikNumpad5; + case "np_6": return DirectInputKeyCode.DikNumpad6; + case "np_7": return DirectInputKeyCode.DikNumpad7; + case "np_8": return DirectInputKeyCode.DikNumpad8; + case "np_9": return DirectInputKeyCode.DikNumpad9; + // Digits + case "0": return DirectInputKeyCode.Dik0; + case "1": return DirectInputKeyCode.Dik1; + case "2": return DirectInputKeyCode.Dik2; + case "3": return DirectInputKeyCode.Dik3; + case "4": return DirectInputKeyCode.Dik4; + case "5": return DirectInputKeyCode.Dik5; + case "6": return DirectInputKeyCode.Dik6; + case "7": return DirectInputKeyCode.Dik7; + case "8": return DirectInputKeyCode.Dik8; + case "9": return DirectInputKeyCode.Dik9; + // navigation + case "insert": return DirectInputKeyCode.DikInsert; + case "home": return DirectInputKeyCode.DikHome; + case "delete": return DirectInputKeyCode.DikDelete; + case "end": return DirectInputKeyCode.DikEnd; + case "pgup": return DirectInputKeyCode.DikPageUp; + case "pgdown": return DirectInputKeyCode.DikPageDown; + case "print": return DirectInputKeyCode.DikPrintscreen; + case "scrolllock": return DirectInputKeyCode.DikScroll; + case "pause": return DirectInputKeyCode.DikPause; + // Arrows + case "up": return DirectInputKeyCode.DikUp; + case "down": return DirectInputKeyCode.DikDown; + case "left": return DirectInputKeyCode.DikLeft; + case "right": return DirectInputKeyCode.DikRight; + // non letters + case "escape": return DirectInputKeyCode.DikEscape; + case "minus": return DirectInputKeyCode.DikMinus; + case "equals": return DirectInputKeyCode.DikEquals; + case "grave": return DirectInputKeyCode.DikGrave; + case "underline": return DirectInputKeyCode.DikUnderline; + case "backspace": return DirectInputKeyCode.DikBackspace; + case "tab": return DirectInputKeyCode.DikTab; + case "lbracket": return DirectInputKeyCode.DikLbracket; + case "rbracket": return DirectInputKeyCode.DikRbracket; + case "enter": return DirectInputKeyCode.DikReturn; + case "capslock": return DirectInputKeyCode.DikCapital; + case "colon": return DirectInputKeyCode.DikColon; + case "backslash": return DirectInputKeyCode.DikBackslash; + case "comma": return DirectInputKeyCode.DikComma; + case "period": return DirectInputKeyCode.DikPeriod; + case "slash": return DirectInputKeyCode.DikSlash; + case "space": return DirectInputKeyCode.DikSpace; + case "semicolon": return DirectInputKeyCode.DikSemicolon; + case "apostrophe": return DirectInputKeyCode.DikApostrophe; + + // all where the lowercase DX name matches the SC name + default: + var letter = "Dik" + scKey.ToUpperInvariant(); + if (Enum.TryParse(letter, out DirectInputKeyCode dxKey)) + { + return dxKey; + } + else + { + return DirectInputKeyCode.DikEscape; + } + } + + } + + + internal static string ExtractMacro(string text, int position) + { + try + { + var endPosition = text.IndexOf(MACRO_END, position); + + // Found an end, let's verify it's actually a macro + if (endPosition > position) + { + // Use Regex to verify it's really a macro + var match = Regex.Match(text.Substring(position, endPosition - position + MACRO_END.Length), REGEX_MACRO); + if (match.Length > 0) + { + return match.Value; + } + } + } + catch (Exception ex) + { + Logger.Instance.LogMessage(TracingLevel.FATAL, $"ExtractMacro Exception: {ex}"); + } + + return null; + } + + internal static List ExtractKeyStrokes(string macroText) + { + var keyStrokes = new List(); + + try + { + var matches = Regex.Matches(macroText, REGEX_SUB_COMMAND); + foreach (var match in matches) + { + var matchText = match.ToString().ToUpperInvariant().Replace("{", "").Replace("}", ""); + + var stroke = (DirectInputKeyCode)Enum.Parse(typeof(DirectInputKeyCode), matchText, true); + + keyStrokes.Add(stroke); + } + } + catch (Exception ex) + { + Logger.Instance.LogMessage(TracingLevel.FATAL, $"ExtractKeyStrokes Exception: {ex}"); + } + + return keyStrokes; + } + } +} diff --git a/starcitizen/CryXMLlib/Conversions.cs b/starcitizen/CryXMLlib/Conversions.cs new file mode 100644 index 0000000..f9df2ca --- /dev/null +++ b/starcitizen/CryXMLlib/Conversions.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Runtime.InteropServices; + +namespace SCJMapper_V2.CryXMLlib +{ + internal static class Extensions + { + /// + /// Get the array slice between the two indexes. + /// ... Inclusive for start index, exclusive end + /// + public static T[] SliceE( this T[] source, UInt32 start, UInt32 end ) + { + // Handles negative ends. + if ( end < 0 ) { + end = ( UInt32 )source.Length + end; + } + UInt32 len = end - start; + + // Return new array. + T[] res = new T[len]; + /* + for ( int i = 0; i < len; i++ ) { + resOLD[i] = source[i + start]; + } + */ + Array.ConstrainedCopy( source, ( int )start, res, 0, ( int )len ); + return res; + } + + /// + /// Get the array slice between the two indexes. + /// ... Inclusive for start index, length. + /// + public static T[] SliceL( this T[] source, UInt32 offset, UInt32 length ) + { + UInt32 end = offset + length; + // Handles negative ends. + if ( end < 0 ) { + end = ( UInt32 )source.Length + end; + } + UInt32 len = end - offset; + + // Return new array. + T[] res = new T[len]; + /* + for ( int i = 0; i < len; i++ ) { + res[i] = source[i + offset]; + } + */ + Array.ConstrainedCopy( source, ( int )offset, res, 0, ( int )len ); + return res; + } + } + + + + internal class Conversions + { + + /// + /// Converts a number of ASCII chars into a string + /// + /// Mem Location of the ASCII Chars + /// Max number of ASCII chars to convert, stops at \0 however + /// The converted string + static public string ToString( byte[] byteArr, uint size = 999 ) + { + string s = ""; + for ( uint i = 0; i < size; i++ ) { + if ( byteArr[i] != 0 ) + s += Char.ConvertFromUtf32( byteArr[i] ); + else + break; // stop at char 0 + } + return s; + } + + /// + /// Allocates and reads bytes of the size of one record + /// and returns the allocated bytes are structure - allowing structured access to binary data + /// Note: there is no error checking whatsoever here - so better make sure everything is OK + /// + /// The record type to read + /// A binary reader + /// The read record + public static T ByteToType( byte[] bytes, UInt32 offset = 0 ) + { + byte[] _bytes = bytes.SliceL( offset, ( UInt32 )Marshal.SizeOf( typeof( T ) ) ); // lets see if this works with Alloc below.. + + GCHandle handle = GCHandle.Alloc( _bytes, GCHandleType.Pinned ); + T theStructure = ( T )Marshal.PtrToStructure( handle.AddrOfPinnedObject( ), typeof( T ) ); + handle.Free( ); + + return theStructure; + } + + + } +} diff --git a/starcitizen/CryXMLlib/CryIXml.cs b/starcitizen/CryXMLlib/CryIXml.cs new file mode 100644 index 0000000..e5fc92c --- /dev/null +++ b/starcitizen/CryXMLlib/CryIXml.cs @@ -0,0 +1,171 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace SCJMapper_V2.CryXMLlib +{ + /// + /// Derived work from CryEngine: IXml.h: + /// + /// Crytek Engine Source File. + /// Copyright (C), Crytek Studios, 2002. + /// ------------------------------------------------------------------------- + /// File name: ixml.h + /// Version: v1.00 + /// Created: 16/7/2002 by Timur. + /// Compilers: Visual Studio.NET + /// Description: + // ------------------------------------------------------------------------- + /// + + + /// + /// kind of typedef (curtesy http://www.codeproject.com/Questions/141385/typedef-in-C) + // Summary: + // Special string wrapper for xml nodes. + /// + public struct XmlString + { + // A struct's fields should not be exposed + private string value; + + // As we are using implicit conversions we can keep the constructor private + private XmlString( string value ) + { + this.value = value; + } + + /// + /// Implicitly converts a XmlString to a . + /// + /// The to convert. + /// A new XmlString with the specified value. + public static implicit operator XmlString( string value ) + { + return new XmlString( value ); + } + /// + /// Implicitly converts a XmlString to a . + /// + /// The XmlString to convert. + /// + /// A that is the specified XmlString's value. + /// + public static implicit operator string( XmlString record ) + { + return record.value; + } + + public static XmlString c_str( byte[] sz, uint len = 999 ) + { + return Conversions.ToString( sz, len ); + } + } + + + /// + /// Abstract IXmlNode class + /// Notes: + /// Never use IXmlNode directly instead use reference counted XmlNodeRef. + /// See also: + /// XmlNodeRef + /// + public abstract class IXmlNode + { + + /// + /// Gets XML node tag. + /// + /// + public abstract string getTag( ); + + /// + /// Returns true if a given tag equal to node tag. + /// + /// The tag + /// True if it is the tag of the node + public abstract bool isTag( string tag ); + + /// + /// Checks if attributes with specified key exist. + /// + /// The attribute key + /// True if this attribute exists + public abstract bool haveAttr( string key ); + + // + /// + /// Gets XML Node attributes count + /// + /// The number of attributes of this node + public abstract int getNumAttributes( ); + + /// + /// Returns attribute key and value by attribute index. + /// + /// The attribute index 0.. + /// Out: the attribute key + /// Out: the attribute value + /// True if returned key and value are valid + public abstract bool getAttributeByIndex( int index, out string key, out string value ); + + /// + /// Gets XML Node attribute for specified key. + /// + /// The attribute key + /// The attribute value or an empty string if it does not exist + public abstract string getAttr( string key ); + + /// + /// Gets XML Node attribute for specified key. + /// + /// The attribute key + /// Out: the attribute value + /// True if the attribute with key exists and the returned value is valid + public abstract bool getAttr( string key, out string value ); + + /// + /// Gets attribute value of node. + /// + /// The attribute key + /// Out: the attribute value as XmlString + /// True if the attribute with key exists and the returned value is valid + public abstract bool getAttr( string key, out XmlString value ); + + /// + /// Gets number of child XML nodes. + /// + /// The number of child nodes of this node + public abstract int getChildCount( ); + + /// + /// Gets XML Node child nodes. + /// + /// The child index of the node to return + /// A valid nodeRef or null if the element does not exist + public abstract CryXmlNodeRef getChild( int i ); + + /// + /// Finds node with specified tag. + /// + /// The node tag of the child node to return + /// A valid nodeRef or null if the element does not exist + public abstract CryXmlNodeRef findChild( string tag ); + + /// + /// Gets parent XML node. + /// + /// A valid nodeRef or null if the element does not exist + public abstract CryXmlNodeRef getParent( ); + + /// + /// Returns content of this node. + /// + /// The node content as string + public abstract string getContent( ); + + } + + +} diff --git a/starcitizen/CryXMLlib/CryXmlBinContext.cs b/starcitizen/CryXMLlib/CryXmlBinContext.cs new file mode 100644 index 0000000..d9d7704 --- /dev/null +++ b/starcitizen/CryXMLlib/CryXmlBinContext.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace SCJMapper_V2.CryXMLlib +{ + /// + /// Derived work from CryEngine: XMLBinaryHeaders.h: + /// CryEngine Source File. + /// Copyright (C), Crytek Studios, 2001-2006. + /// ------------------------------------------------------------------------- + /// File name: xml.h + /// Created: 21/04/2006 by Timur. + /// Description: + /// ------------------------------------------------------------------------- + /// + /// + + + /// + /// Memory context of the binary XML file + /// + internal class CryXmlBinContext // CBinaryXmlData + { + + public CryXMLNode[] pNodes = null; // gets a copy of all Node entries + public CryXMLAttribute[] pAttributes= null; // gets a copy of all Attribute entries + public CryXMLNodeIndex[] pChildIndices= null; // gets a copy of all Note relations + public byte[] pStringData = null; // gets a copy of the string data + public UInt32 pStringDataLength = 0; // length of the string data + + /// + /// Returns an XMLString from the stringData area + /// + /// The start offset of the string to return + /// The string + public XmlString _string( UInt32 sOffset ) + { + return Conversions.ToString( pStringData.SliceE( sOffset, pStringDataLength ) ); + } + + public List pBinaryNodes= null; // list of binary nodes - one to one with the real nodes + } + + +} diff --git a/starcitizen/CryXMLlib/CryXmlBinHeader.cs b/starcitizen/CryXMLlib/CryXmlBinHeader.cs new file mode 100644 index 0000000..35f74ce --- /dev/null +++ b/starcitizen/CryXMLlib/CryXmlBinHeader.cs @@ -0,0 +1,154 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Runtime.InteropServices; + +namespace SCJMapper_V2.CryXMLlib +{ + /// + /// Derived (file structure) work from CryEngine: XMLBinaryHeaders.h: + /// --------------------------------------------------------------------------- + /// Copyright 2006 Crytek GmbH + /// Created by: Michael Smith + ///--------------------------------------------------------------------------- + /// + + + /// + /// kind of typedef (curtesy http://www.codeproject.com/Questions/141385/typedef-in-C) + /// A wrapper around . + /// + internal struct CryXMLNodeIndex + { + static public UInt32 MySize( ) { return ( UInt32 )Marshal.SizeOf( typeof( CryXMLNodeIndex ) ); } + + private UInt32 value; + + // As we are using implicit conversions we can keep the constructor private + private CryXMLNodeIndex( UInt32 value ) + { + this.value = value; + } + private CryXMLNodeIndex( int value ) + { + this.value = ( CryXMLNodeIndex )value; + } + + /// + /// Implicitly converts a to a Record. + /// + /// The to convert. + /// A new Record with the specified value. + public static implicit operator CryXMLNodeIndex( UInt32 value ) + { + return new CryXMLNodeIndex( value ); + } + public static implicit operator CryXMLNodeIndex( int value ) + { + return new CryXMLNodeIndex( value ); + } + /// + /// Implicitly converts a Record to a . + /// + /// The Record to convert. + /// + /// A that is the specified Record's value. + /// + public static implicit operator UInt32( CryXMLNodeIndex record ) + { + return record.value; + } + public static implicit operator int( CryXMLNodeIndex record ) + { + return ( int )record.value; + } + } + + + /// + /// Maps the Node from binary file to memory + /// + [StructLayout( LayoutKind.Sequential, Pack = 1 )] //, Size = 5 * 4 + 2 * 2 = 24 (28 according to dump) + internal struct CryXMLNode + { + static public UInt32 MySize( ) { return ( UInt32 )Marshal.SizeOf( typeof( CryXMLNode ) ); } + + public CryXMLNodeIndex nParentIndex { get { return _nParentIndex; } } // type conversion only + public CryXMLNodeIndex nFirstAttributeIndex { get { return _nFirstAttributeIndex; } } // type conversion only + public CryXMLNodeIndex nFirstChildIndex { get { return _nFirstChildIndex; } } // type conversion only + + [MarshalAs( UnmanagedType.U4 )] + public UInt32 nTagStringOffset; // offset in CBinaryXmlData::pStringData + [MarshalAs( UnmanagedType.U4 )] + public UInt32 nContentStringOffset; // offset in CBinaryXmlData::pStringData + [MarshalAs( UnmanagedType.U2 )] + public UInt16 nAttributeCount; + [MarshalAs( UnmanagedType.U2 )] + public UInt16 nChildCount; + [MarshalAs( UnmanagedType.U4 )] + private UInt32 _nParentIndex; + [MarshalAs( UnmanagedType.U4 )] + private UInt32 _nFirstAttributeIndex; + [MarshalAs( UnmanagedType.U4 )] + private UInt32 _nFirstChildIndex; + + [MarshalAs( UnmanagedType.U4 )] + private UInt32 _PAD; // according to hex analysis we have a 4 byte pad at the end of each node + } + + + /// + /// Maps the Attribute from binary file to memory + /// + [StructLayout( LayoutKind.Sequential, Pack = 1 )] //, Size = 2 * 4 = 8 (OK) + internal struct CryXMLAttribute + { + static public UInt32 MySize( ) { return ( UInt32 )Marshal.SizeOf( typeof( CryXMLAttribute ) ); } + + [MarshalAs( UnmanagedType.U4 )] + public UInt32 nKeyStringOffset; // offset in CBinaryXmlData::pStringData + [MarshalAs( UnmanagedType.U4 )] + public UInt32 nValueStringOffset; // offset in CBinaryXmlData::pStringData + } + + + /// + /// Maps the Header from binary file to memory + /// + [StructLayout( LayoutKind.Sequential, Pack = 1 )] //, Size = 9 * 4 + 8 = 44 + internal struct CryXMLHeader + { + static public UInt32 MySize( ) { return ( UInt32 )Marshal.SizeOf( typeof( CryXMLHeader ) ); } + + public bool HasCorrectSignature { get { return ( szSignature == "CryXmlB" ); } } + + public string szSignature { get { return Conversions.ToString( _szSignature, 8 ); } } // from ASCIIZ + + [MarshalAs( UnmanagedType.ByValArray, SizeConst = 8 )] + private byte[] _szSignature; + [MarshalAs( UnmanagedType.U4 )] + public UInt32 nXMLSize; + [MarshalAs( UnmanagedType.U4 )] + public UInt32 nNodeTablePosition; + [MarshalAs( UnmanagedType.U4 )] + public UInt32 nNodeCount; + [MarshalAs( UnmanagedType.U4 )] + public UInt32 nAttributeTablePosition; + [MarshalAs( UnmanagedType.U4 )] + public UInt32 nAttributeCount; + [MarshalAs( UnmanagedType.U4 )] + public UInt32 nChildTablePosition; + [MarshalAs( UnmanagedType.U4 )] + public UInt32 nChildCount; + [MarshalAs( UnmanagedType.U4 )] + public UInt32 nStringDataPosition; + [MarshalAs( UnmanagedType.U4 )] + public UInt32 nStringDataSize; + + } + + + + +} diff --git a/starcitizen/CryXMLlib/CryXmlBinNode.cs b/starcitizen/CryXMLlib/CryXmlBinNode.cs new file mode 100644 index 0000000..09b0d6a --- /dev/null +++ b/starcitizen/CryXMLlib/CryXmlBinNode.cs @@ -0,0 +1,180 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace SCJMapper_V2.CryXMLlib +{ + /// + /// Derived work from CryEngine: XMLBinaryHeaders.h: + /// CryEngine Source File. + /// Copyright (C), Crytek Studios, 2001-2006. + /// ------------------------------------------------------------------------- + /// File name: xml.h + /// Created: 21/04/2006 by Timur. + /// Description: + /// ------------------------------------------------------------------------- + /// + /// + + /// + /// Implemented IXmlNode + /// + internal class CryXmlBinNode : IXmlNode // CBinaryXmlNode + { + + internal CryXmlBinContext m_pData = null; // ref to the binary data area + internal UInt32 m_pNodeIndex = 0; // Index of ourself + + // Return current node in binary data. + private CryXMLNode _node( ) + { + return m_pData.pNodes[m_pNodeIndex]; + } + + private XmlString _string( UInt32 nIndex ) + { + return m_pData._string( nIndex ); + } + + private string GetValue( string key ) + { + CryXMLNodeIndex nFirst = _node( ).nFirstAttributeIndex; + CryXMLNodeIndex nLast = nFirst + _node( ).nAttributeCount; + for ( CryXMLNodeIndex i = nFirst; i < nLast; i++ ) { + XmlString attrKey = _string( m_pData.pAttributes[i].nKeyStringOffset ); + if ( key == attrKey ) { + string attrValue = _string( m_pData.pAttributes[i].nValueStringOffset ); + return attrValue; + } + } + return ""; + } + + + // Get XML node tag. + public override string getTag( ) + { + return _string( _node( ).nTagStringOffset ); + } + + // Return true if given tag is equal to node tag. + public override bool isTag( string tag ) + { + return ( tag == getTag( ) ); + } + + + // Check if attributes with specified key exist. + public override bool haveAttr( string key ) + { + return ( !string.IsNullOrEmpty( GetValue( key ) ) ); + } + + // Get XML Node attributes. + public override int getNumAttributes( ) { return ( int )_node( ).nAttributeCount; } + + // Return attribute key and value by attribute index. + public override bool getAttributeByIndex( int index, out string key, out string value ) + { + key = ""; value = ""; + + CryXMLNode pNode = _node( ); + if ( index >= 0 && index < pNode.nAttributeCount ) { + CryXMLAttribute attr = m_pData.pAttributes[pNode.nFirstAttributeIndex + index]; + key = _string( attr.nKeyStringOffset ); + value = _string( attr.nValueStringOffset ); + return true; + } + return false; + } + + // Return attribute key and value by attribute index, string version. + public virtual bool getAttributeByIndex( int index, out XmlString key, out XmlString value ) + { + string _key, _value; + bool retVal = getAttributeByIndex( index, out _key, out _value ); + key = ( XmlString )_key; value = ( XmlString )_value; + return retVal; + } + + // Get XML Node attribute for specified key. + public override string getAttr( string key ) + { + return GetValue( key ); + } + + // Get XML Node attribute for specified key. + // Returns true if the attribute exists, false otherwise. + public override bool getAttr( string key, out string value ) + { + string svalue = GetValue( key ); + if ( !string.IsNullOrEmpty( svalue ) ) { + value = svalue; + return true; + } + else { + value = ""; + return false; + } + } + + // Get attribute value of node. + public override bool getAttr( string key, out XmlString value ) + { + string v = ""; + bool boHasAttribute = getAttr( key, out v ); + value = v; + return boHasAttribute; + } + + // Get number of child XML nodes. + public override int getChildCount( ) { return ( int )_node( ).nChildCount; } + + // Get XML Node child nodes. + public override CryXmlNodeRef getChild( int i ) + { + CryXMLNode pNode = _node( ); + if ( i < 0 || i > ( int )pNode.nChildCount ) { + return null; + } + CryXmlNodeRef n = m_pData.pBinaryNodes[m_pData.pChildIndices[pNode.nFirstChildIndex + i]]; + return n; + } + + // Find node with specified tag. + public override CryXmlNodeRef findChild( string tag ) + { + CryXMLNode pNode = _node( ); + CryXMLNodeIndex nFirst = pNode.nFirstChildIndex; + CryXMLNodeIndex nAfterLast = pNode.nFirstChildIndex + pNode.nChildCount; + for ( CryXMLNodeIndex i = nFirst; i < nAfterLast; i++ ) { + string sChildTag = _string( m_pData.pNodes[m_pData.pChildIndices[i]].nTagStringOffset ); + if ( tag == sChildTag ) { + CryXmlNodeRef n = m_pData.pBinaryNodes[m_pData.pChildIndices[i]]; + return n; + } + } + return null; + } + + + // Get parent XML node. + public override CryXmlNodeRef getParent( ) + { + CryXMLNode pNode = _node( ); + if ( pNode.nParentIndex != ( CryXMLNodeIndex )( -1 ) ) { // murks.. + CryXmlNodeRef n = m_pData.pBinaryNodes[pNode.nParentIndex]; + return n; + } + // has no parent i.e. toplevel + return this; + } + + // Returns content of this node. + public override string getContent( ) { return _string( _node( ).nContentStringOffset ); } + + + } + +} diff --git a/starcitizen/CryXMLlib/CryXmlBinReader.cs b/starcitizen/CryXMLlib/CryXmlBinReader.cs new file mode 100644 index 0000000..657d5e0 --- /dev/null +++ b/starcitizen/CryXMLlib/CryXmlBinReader.cs @@ -0,0 +1,227 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; +using System.Runtime.InteropServices; + +namespace SCJMapper_V2.CryXMLlib +{ + /// + /// Inspired... by work from CryEngine: XMLBinaryReader.h/.cpp: + /// --------------------------------------------------------------------------- + /// Copyright 2006 Crytek GmbH + /// Created by: Michael Smith + /// --------------------------------------------------------------------------- + /// + /// BUT uses a complete different memory management and processing eliminating extensive Ptr juggling from C++ + /// + public class CryXmlBinReader + { + /// + /// The processing result Enum + /// + public enum EResult + { + Success, + NotBinXml, + Error, + } + + private string m_errorDescription = ""; + private void SetErrorDescription( string text ) + { + m_errorDescription = text; + } + + /// + /// Get error information if something goes wrong + /// + /// The error description + public string GetErrorDescription( ) { return m_errorDescription; } + + /// + /// Load a Cry Binary XML file into memory and return the NodeRef for the root element + /// + /// The file to read + /// Read result + /// The NodeRef of the root element or NULL + public CryXmlNodeRef LoadFromFile( string filename, out EResult result ) + { + m_errorDescription = ""; + result = EResult.Error; + + if ( !File.Exists( filename ) ) { + SetErrorDescription( "Can't open file (file not found)." ); + return null; + } + + using ( BinaryReader binReader = new BinaryReader( File.Open( filename, FileMode.Open ) ) ) { + try { + UInt32 fileSize = ( UInt32 )binReader.BaseStream.Length; + + if ( fileSize < CryXMLHeader.MySize( ) ) { + result = EResult.NotBinXml; + SetErrorDescription( "File is not a binary XML file (file size is too small)." ); + return null; + } + + // read from binary file and map the content into the memory + CryXmlBinContext pData = Create( binReader, fileSize, out result ); + + if ( result != EResult.Success ) return null; // Well... + + // Return first node + CryXmlNodeRef n = pData.pBinaryNodes[0]; + return n; + + } catch { + result = EResult.NotBinXml; + SetErrorDescription( "Exception in BinaryReader." ); + return null; + } + } + } + + + /// + /// Load a Cry Binary XML buffer into memory and return the NodeRef for the root element + /// + /// The byte buffer to read + /// Read result + /// The NodeRef of the root element or NULL + public CryXmlNodeRef LoadFromBuffer( byte[] binBuffer, out EResult result ) + { + m_errorDescription = ""; + result = EResult.Error; + + UInt32 fileSize = ( UInt32 )binBuffer.Length; + + try { + if ( fileSize < CryXMLHeader.MySize( ) ) { + result = EResult.NotBinXml; + SetErrorDescription( "File is not a binary XML file (file size is too small)." ); + return null; + } + + // read from binary file and map the content into the memory + CryXmlBinContext pData = Create( binBuffer, out result ); + + if ( result != EResult.Success ) return null; // Well... + + // Return first node + CryXmlNodeRef n = pData.pBinaryNodes[0]; + return n; + + } catch { + result = EResult.NotBinXml; + SetErrorDescription( "Exception in buffer reader" ); + return null; + } + } + + + /// + /// Reads the binary file into the internal structures + /// Note: use GetErrorDescription() if the result is not Success + /// + /// An open binary reader + /// The length to read + /// Out: the result of the collection of file content + /// A valid memory context or null + private CryXmlBinContext Create( BinaryReader bReader, UInt32 size, out EResult result ) + { + result = EResult.Error; + + // read data from file into a local buffer + byte[] fileContents = bReader.ReadBytes( ( int )size ); // get all from the reader + + return Create( fileContents, out result ); + } + + + /// + /// Reads the binary buffer into the internal structures + /// Note: use GetErrorDescription() if the result is not Success + /// + /// An filled byte buffer + /// Out: the result of the collection of file content + /// A valid memory context or null + private CryXmlBinContext Create( byte[] fileContents, out EResult result ) + { + result = EResult.Error; + + CryXmlBinContext pData = new CryXmlBinContext( ); + if ( pData == null ) { + SetErrorDescription( "Can't allocate memory for binary XML object." ); + return null; + } + + CryXMLHeader header = Conversions.ByteToType( fileContents ); // reads the header, mapping from binary to struct + if ( !header.HasCorrectSignature ) { + SetErrorDescription( "File is not a binary XML object (wrong header signature)." ); + return null; + } + + // Create binary nodes to wrap the ones to read later + pData.pBinaryNodes = new List( ); // dynamic list used, not an array + for ( int i = 0; i < header.nNodeCount; i++ ) { pData.pBinaryNodes.Add( new CryXmlBinNode( ) ); } + + // map file content to binary.. here we really allocate arrays of elements and copy rather than the original which worked well with ptrs in c++ + + try { + pData.pAttributes = ( CryXMLAttribute[] )Array.CreateInstance( typeof( CryXMLAttribute ), header.nAttributeCount ); // alloc enough + UInt32 incr = CryXMLAttribute.MySize( ); // size of one element to read + for ( UInt32 aIdx = 0; aIdx < header.nAttributeCount; aIdx++ ) { + pData.pAttributes[aIdx] = Conversions.ByteToType( fileContents, header.nAttributeTablePosition + aIdx * incr ); + } + } catch ( Exception e ) { + SetErrorDescription( string.Format( "EXC Attributes: {0}", e.Message ) ); + return null; + } + + try { + pData.pChildIndices = ( CryXMLNodeIndex[] )Array.CreateInstance( typeof( CryXMLNodeIndex ), header.nChildCount ); // alloc enough + UInt32 incr = CryXMLNodeIndex.MySize( ); // size of one element to read + for ( UInt32 aIdx = 0; aIdx < header.nChildCount; aIdx++ ) { + pData.pChildIndices[aIdx] = Conversions.ByteToType( fileContents, header.nChildTablePosition + aIdx * incr ); + } + } catch ( Exception e ) { + SetErrorDescription( string.Format( "EXC ChildIndices: {0}", e.Message ) ); + return null; + } + + try { + pData.pNodes = ( CryXMLNode[] )Array.CreateInstance( typeof( CryXMLNode ), header.nNodeCount ); // alloc enough + UInt32 incr = CryXMLNode.MySize( ); // size of one element to read + for ( UInt32 aIdx = 0; aIdx < header.nNodeCount; aIdx++ ) { + pData.pNodes[aIdx] = Conversions.ByteToType( fileContents, header.nNodeTablePosition + aIdx * incr ); + } + } catch ( Exception e ) { + SetErrorDescription( string.Format( "EXC Nodes: {0}", e.Message ) ); + return null; + } + + try { + pData.pStringDataLength = header.nStringDataSize; + pData.pStringData = fileContents.SliceL( header.nStringDataPosition, header.nStringDataSize ); + } catch ( Exception e ) { + SetErrorDescription( string.Format( "EXC StringData: {0}", e.Message ) ); + return null; + } + + // init binary nodes + for ( UInt32 nNode = 0; nNode < header.nNodeCount; ++nNode ) { + pData.pBinaryNodes[( int )nNode].m_pData = pData; // add data space + pData.pBinaryNodes[( int )nNode].m_pNodeIndex = nNode; // self ref.. + } + + // and back.. + result = EResult.Success; + return pData; + } + + } + + +} diff --git a/starcitizen/CryXMLlib/CryXmlNodeRef.cs b/starcitizen/CryXMLlib/CryXmlNodeRef.cs new file mode 100644 index 0000000..b682649 --- /dev/null +++ b/starcitizen/CryXMLlib/CryXmlNodeRef.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace SCJMapper_V2.CryXMLlib +{ + /// + /// Derived work from CryEngine: IXml.h: + /// + /// Crytek Engine Source File. + /// Copyright (C), Crytek Studios, 2002. + /// ------------------------------------------------------------------------- + /// File name: ixml.h + /// Version: v1.00 + /// Created: 16/7/2002 by Timur. + /// Compilers: Visual Studio.NET + /// Description: + // ------------------------------------------------------------------------- + /// + + // Summary: + // XmlNodeRef, wrapper class IXmlNode. + // See also: + // IXmlNode + public class CryXmlNodeRef + { + // CLASS + private IXmlNode p = null; + + public CryXmlNodeRef( ) { } + public CryXmlNodeRef( IXmlNode p_ ) + { + p = p_; + } + public CryXmlNodeRef( CryXmlNodeRef p_ ) + { + p = p_.p; + } + + // conversions + + /// + /// Implicitly converts a XmlString to a IXmlNode. + /// + /// The IXmlNode to convert. + /// A new XmlString with the specified value. + public static implicit operator CryXmlNodeRef( IXmlNode value ) + { + return new CryXmlNodeRef( value ); + } + + /// + /// Implicitly converts a IXmlNode to a XmlNodeRef. + /// + /// The XmlNodeRef to convert. + /// A new IXmlNode with the specified value. + public static implicit operator IXmlNode( CryXmlNodeRef value ) + { + return value.p; + } + + // Misc compare functions. + public static bool operator ==( CryXmlNodeRef p1, CryXmlNodeRef p2 ) + { + // If both are null, or both are same instance, return true. + if ( System.Object.ReferenceEquals( p1, p2 ) ) { + return true; + } + + // If one is null, but not both, return false. + if ( ( ( object )p1 == null ) || ( ( object )p2 == null ) ) { + return false; + } + + // Return true if the fields match: + return p1 == p2; + + } + public static bool operator !=( CryXmlNodeRef p1, CryXmlNodeRef p2 ) { return p1 != p2; } + + public override bool Equals( System.Object obj ) + { + // If parameter is null return false. + if ( obj == null ) { + return false; + } + + // If parameter cannot be cast to Point return false. + CryXmlNodeRef objP = obj as CryXmlNodeRef; + if ( ( System.Object )p == null ) { + return false; + } + + // Return true if the fields match: + return ( p == objP.p ); + } + + public bool Equals( CryXmlNodeRef objP ) + { + // If parameter is null return false: + if ( ( object )objP == null ) { + return false; + } + + // Return true if the fields match: + return ( p == objP.p ); + } + + public override int GetHashCode( ) + { + return base.GetHashCode( ) ^ p.GetHashCode( ); + } + } + +} diff --git a/starcitizen/CryXMLlib/XmlTree.cs b/starcitizen/CryXMLlib/XmlTree.cs new file mode 100644 index 0000000..0d7cf7c --- /dev/null +++ b/starcitizen/CryXMLlib/XmlTree.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace SCJMapper_V2.CryXMLlib +{ + /// + /// Processes a CryXmlNodeRef and reports the node and its childs as XML string list + /// + public class XmlTree + { + + private List m_doc = new List( ); // internal list of strings + + /// + /// Return the derived XML text as List of strings + /// + public List XML_list { get { return m_doc; } } + + /// + /// Return the derived XML text as string + /// + public string XML_string + { + get { + string xml = ""; string CR = string.Format("\n"); + foreach ( string s in m_doc ) xml += ( s + CR ); + return xml; + } + } + + + /// + /// Processes all attributed of a node + /// + /// The node to process + /// an string containing all attributes in XML compatible format ( key="value" ) + private string DoAttribute( CryXmlNodeRef nodeRef ) + { + IXmlNode node = nodeRef; + string xml = ""; + + // collect all attributes into one line + for ( int ac=0; ac < node.getNumAttributes( ); ac++ ) { + string key = ""; string value = ""; + node.getAttributeByIndex(ac, out key, out value ); + xml += string.Format( " {0}=\"{1}\" ", key, value); + } + return xml; + } + + /// + /// Processes a node and it's children + /// + /// The node to process + /// The depth of the node to indent the XML text + private void DoNode( CryXmlNodeRef nodeRef, int level ) + { + string tabs = "".PadRight(level, '\t'); // level is depth - will be left padded with Tabs on Add() + string xml = ""; + + IXmlNode node = nodeRef; + + // first gather and handle the attributes + string attr = DoAttribute( nodeRef ); + xml = string.Format( "<{0} {1} ", node.getTag( ), attr ); + + // then do some formatting dependent of child nodes to be printed + if ( node.getChildCount( ) < 1 ) { + // no child - close with end tag immediately + xml += string.Format( "/>" ); m_doc.Add( tabs + xml ); // add line w/o NL + } + else { + // with children - close tag only + xml += string.Format( ">" ); m_doc.Add( tabs + xml ); // add line w/o NL + + // do the children + for ( int cc=0; cc < node.getChildCount( ); cc++ ) { + CryXmlNodeRef childRef = node.getChild( cc ); + DoNode( childRef, level+1 ); // recursion + } + xml = string.Format( "{0}>\n", node.getTag( ) ); m_doc.Add( tabs + xml ); // add line with NL to space them + } + } + + + /// + /// Processes a CryXmlNodeRef to derive the XML formatted structure + /// Note: the created XML text can be retrieved through the XML property of this object + /// + /// The node to start from + public void BuildXML( CryXmlNodeRef rootRef ) + { + m_doc.Clear( ); + + DoNode( rootRef, 0 ); + } + + } +} diff --git a/starcitizen/Images/Default.png b/starcitizen/Images/Default.png new file mode 100644 index 0000000..27f36e2 Binary files /dev/null and b/starcitizen/Images/Default.png differ diff --git a/starcitizen/Images/categoryIcon.png b/starcitizen/Images/categoryIcon.png new file mode 100644 index 0000000..5bb795c Binary files /dev/null and b/starcitizen/Images/categoryIcon.png differ diff --git a/starcitizen/Images/categoryIcon@2x.png b/starcitizen/Images/categoryIcon@2x.png new file mode 100644 index 0000000..33830ce Binary files /dev/null and b/starcitizen/Images/categoryIcon@2x.png differ diff --git a/starcitizen/Images/icon.png b/starcitizen/Images/icon.png new file mode 100644 index 0000000..69e7b4a Binary files /dev/null and b/starcitizen/Images/icon.png differ diff --git a/starcitizen/Images/icon@2x.png b/starcitizen/Images/icon@2x.png new file mode 100644 index 0000000..fa6d11f Binary files /dev/null and b/starcitizen/Images/icon@2x.png differ diff --git a/starcitizen/Images/pluginIcon.png b/starcitizen/Images/pluginIcon.png new file mode 100644 index 0000000..7a49d93 Binary files /dev/null and b/starcitizen/Images/pluginIcon.png differ diff --git a/starcitizen/Images/pluginIcon@2x.png b/starcitizen/Images/pluginIcon@2x.png new file mode 100644 index 0000000..7344a57 Binary files /dev/null and b/starcitizen/Images/pluginIcon@2x.png differ diff --git a/starcitizen/Program.cs b/starcitizen/Program.cs new file mode 100644 index 0000000..a4ab59a --- /dev/null +++ b/starcitizen/Program.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BarRaider.SdTools; +using p4ktest.SC; +using SCJMapper_V2.SC; + +namespace starcitizen +{ + class Program + { + public static DProfileReader dpReader = new DProfileReader(); // we may read a profile + + static void Main(string[] args) + { + Logger.Instance.LogMessage(TracingLevel.INFO, "Init Star Citizen"); + + + try + { + + SCFiles.Instance.UpdatePack(); // update game files + + var profile = SCDefaultProfile.DefaultProfile(); + + var actionmaps = SCDefaultProfile.ActionMaps(); + + dpReader.fromXML(profile); + + dpReader.fromActionProfile(actionmaps); + + dpReader.Actions(); + + dpReader.CreateDropdownTemplate(); + + dpReader.CreateCsv(); + + } + catch (Exception ex) + { + Logger.Instance.LogMessage(TracingLevel.FATAL, $"DProfileReader: {ex}"); + } + + Logger.Instance.LogMessage(TracingLevel.INFO, "Finished Init Star Citizen"); + + //var langFiles = SCFiles.Instance.LangFiles; + //var langFile = SCFiles.Instance.LangFile(langFiles[0]); + //var txt = SCUiText.Instance.Text("@ui_COMiningThrottle", "???"); + + // Write the string array to a new file named "WriteLines.txt". + + + // Uncomment this line of code to allow for debugging + //while (!System.Diagnostics.Debugger.IsAttached) { System.Threading.Thread.Sleep(100); } + + SDWrapper.Run(args); + + + } + } +} diff --git a/starcitizen/Properties/AssemblyInfo.cs b/starcitizen/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d55f8a8 --- /dev/null +++ b/starcitizen/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Star Citizen Buttons")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Star Citizen Buttons")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("761fcc88-eaf9-4c7a-bbfd-139d186437a5")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/starcitizen/PropertyInspector/StarCitizen/Static.html b/starcitizen/PropertyInspector/StarCitizen/Static.html new file mode 100644 index 0000000..7253fcc --- /dev/null +++ b/starcitizen/PropertyInspector/StarCitizen/Static.html @@ -0,0 +1,324 @@ + + + + + + + + Mhwlng's Star Citizen + + + + + + + + + + + Function + + + + Advanced Camera Controls Modifier (Hold) + Advanced Camera Controls Modifier (Hold) + Clear Saved View + Decrease DoF + Decrease FoV + Increase DoF + Increase FoV + Load View 1 + Load View 2 + Load View 3 + Load View 4 + Load View 5 + Load View 6 + Load View 7 + Load View 8 + Load View 9 + Reset Current View + Save View 1 + Save View 2 + Save View 3 + Save View 4 + Save View 5 + Save View 6 + Save View 7 + Save View 8 + Save View 9 + X Offset Negative + X Offset Positive + Y Offset Negative / Spectator Freecam Focal Point Backward + Y Offset Positive / Spectator Freecam Focal Point Forward + Z Offset Negative + Z Offset Positive + + + @ui_CIEVADetach + @ui_CIEVALaunch + @ui_CIEVAPushBack + @ui_CIEVAPushForward + Boost + Brake + Freelook (Hold) + Roll Left + Roll Right + Strafe Backward + Strafe Down + Strafe Forward + Strafe Left + Strafe Right + Strafe Up + + + Spectator Camera HUD (Toggle) + Spectator Camera Lock Target + Spectator Camera Mode (Next) + + + Eject + Emergency Exit Seat + Flight / Systems Ready + Leave Vehicle Seat (Hold) + Self Destruct + + + Decoy - Decrease Burst Size (tap) + Decoy - Increase Burst Size (tap) + Decoy - Launch Burst (tap), Set and Launch Burst (hold) + Noise - Deploy (tab) + Shield raise level back + Shield raise level bottom + Shield raise level front + Shield raise level left + Shield raise level right + Shield raise level top + Shield reset levels + + + Map + mobiGlas (Toggle) + Scoreboard + Wipe Helmet Visor + + + Activate Mining Module (Slot 1) + Activate Mining Module (Slot 2) + Activate Mining Module (Slot 3) + Jettison Cargo + Mining Mode (Toggle) + + + @ui_CIDockToggleView + Acceleration Limiter Up / Down (rel.) + Afterburner + Autoland + Cruise Control (Toggle) + Decoupled mode (Toggle) + Landing System (Toggle) + Lock Pitch / Yaw Movement (Toggle / Hold) + Quantum Drive + Quantum Travel System (Toggle) + Roll left + Roll right + Spacebrake + Strafe down + Strafe left + Strafe right + Strafe up + Throttle back + Throttle forward + Toggle VTOL + + + Decrease Throttle + Decrease Throttle to Min + Increase Priority - Shields + Increase Priority - Thrusters + Increase Priority - Weapons + Increase Throttle + Increase Throttle to Max + Reset Priority + Toggle Power - All + Toggle Power - Shields + Toggle Power - Thrusters + Toggle Power - Weapons + + + Scanning Mode (Toggle) + + + Cycle Lock - All - Forward + Cycle Lock - All - Reset to Closest + Cycle Lock - Attackers - Forward + Cycle Lock - Attackers - Reset to Closest + Cycle Lock - Friendlies - Forward + Cycle Lock - Friendlies - Reset to Closest + Cycle Lock - Hostiles - Forward + Cycle Lock - Hostiles - Reset to Closest + Cycle Lock - In View - Forward + Cycle Lock - In View - Under Reticle + Cycle Lock - Sub-Target - Forward + Cycle Lock - Sub-Target - Reset to Main Target + Cycle Selection - Forward + Cycle Selection - Reset to Auto + + + Hail Target + + + Enable / Disable Look Ahead + Pin Index 1 - Lock / Unlock Pinned Target + Pin Index 1 - Pin / Unpin Selected Target + Pin Index 2 - Lock / Unlock Pinned Target + Pin Index 2 - Pin / Unpin Selected Target + Pin Index 3 - Lock / Unlock Pinned Target + Pin Index 3 - Pin / Unpin Selected Target + Remove All Pinned Targets + Unlock Locked Target + + + Cycle camera view + Dynamic Zoom In and Out (rel.) + Freelook (Hold) + + + Cycle Gimbal Assist / Standard Gimbal / Gimbal Lock modes + Manual Gimbal Mode - Lock Aim Vector + Manual Gimbal Mode - Swap VJoy / Look Direction (Toggle, Hold) + + + Cycle camera view + Flight / Systems Ready + Freelook (Hold) + Horn + Leave Vehicle Seat (Hold) + Map + mobiGlas (Toggle) + Wipe Helmet Visor + + + @ui_CI_MGV_ToggleBreakOnIdle + @ui_CIboost + Brake + Drive Backward + Drive Forward + Dynamic Zoom In and Out (rel.) + Lock Pitch / Yaw Movement (Toggle / Hold) + Turn Left + Turn Right + + + Headlights (Toggle) + + + Change Fire Mode + Crouch + Customize Weapon + Dodge Back + Dodge left + Dodge Right + Flashlight (Toggle) + Force Re-spawn (E.V.A. / On Foot) + FPS Underbarrel Attachment Action + Free View Camera (Hold) + Hold Breath (ADS) + Holster Weapon + Jump + Lean Left + Lean Right + Map + mobiGlas (Toggle) + Move Backwards + Move Forward + Move Left + Move Right + Prone + Reload + Scoreboard + Select Contract Item + Select Gadget + Select Melee + Select Primary Weapon + Select Secondary Weapon + Select Sidearm + Sprint + Third Person View (Toggle) + Unarmed Combat + Weapon Zeroing Decrease + Weapon Zeroing Increase / Auto + Wipe Helmet Visor + + + @ui_Consumable_QuickSelectRadialMenu + Exit + Flight Mode Select Radial Menu + Interaction Mode + MFD Down + MFD Left + MFD Right + MFD Up + Mining Mode Actions - PIT Category + Personal Commodity Inventory (Toggle) + Personal Inner Thought (PIT) + Throwable Select Radial Menu + Weapon Select Radial Menu + Weapon Select Radial Menu + Weapon Select Radial Menu + + + Forward + Left + No + Right + Stop + Yes + + + Chat Window (Toggle) + CommLink App (Toggle) + Exit seat + Re-spawn + + + Accept Invite + Ignore Invite (hold) + Reject Invite + + + [PH] Turret - Speed Limiter - Decrease (rel) + [PH] Turret - Speed Limiter - Increase (rel) + Cycle fire mode (staggered / combined) + Recenter Turret (Hold) + Toggle E.S.P. on / off + Turret - Speed Limiter - On/Off (Hold/Toggle) + Turret Gyro Stabilization (Toggle) + + + Exit Remote Turret + Toggle Turret Mouse Movement (VJoy, FPS style) + + + Cycle through audio channels + Enable Head Tracking (Toggle) + FOIP Recalibrate + FOIP Selfie Cam + VOIP Push To Talk + VOIP Push To Talk (Proximity only) + + + + + + + Sound + + + No file... + Choose file... + + + + + + diff --git a/starcitizen/PropertyInspector/caret.svg b/starcitizen/PropertyInspector/caret.svg new file mode 100644 index 0000000..b69162a --- /dev/null +++ b/starcitizen/PropertyInspector/caret.svg @@ -0,0 +1,3 @@ + + + diff --git a/starcitizen/PropertyInspector/check.png b/starcitizen/PropertyInspector/check.png new file mode 100644 index 0000000..b5e9e62 Binary files /dev/null and b/starcitizen/PropertyInspector/check.png differ diff --git a/starcitizen/PropertyInspector/check.svg b/starcitizen/PropertyInspector/check.svg new file mode 100644 index 0000000..5b96af0 --- /dev/null +++ b/starcitizen/PropertyInspector/check.svg @@ -0,0 +1,3 @@ + + + diff --git a/starcitizen/PropertyInspector/elg_calendar.svg b/starcitizen/PropertyInspector/elg_calendar.svg new file mode 100644 index 0000000..157e01b --- /dev/null +++ b/starcitizen/PropertyInspector/elg_calendar.svg @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/starcitizen/PropertyInspector/elg_calendar_inv.svg b/starcitizen/PropertyInspector/elg_calendar_inv.svg new file mode 100644 index 0000000..4f8af68 --- /dev/null +++ b/starcitizen/PropertyInspector/elg_calendar_inv.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/starcitizen/PropertyInspector/jquery-3.3.1.min.js b/starcitizen/PropertyInspector/jquery-3.3.1.min.js new file mode 100644 index 0000000..4d9b3a2 --- /dev/null +++ b/starcitizen/PropertyInspector/jquery-3.3.1.min.js @@ -0,0 +1,2 @@ +/*! jQuery v3.3.1 | (c) JS Foundation and other contributors | jquery.org/license */ +!function(e,t){"use strict";"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("jQuery requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(e,t){"use strict";var n=[],r=e.document,i=Object.getPrototypeOf,o=n.slice,a=n.concat,s=n.push,u=n.indexOf,l={},c=l.toString,f=l.hasOwnProperty,p=f.toString,d=p.call(Object),h={},g=function e(t){return"function"==typeof t&&"number"!=typeof t.nodeType},y=function e(t){return null!=t&&t===t.window},v={type:!0,src:!0,noModule:!0};function m(e,t,n){var i,o=(t=t||r).createElement("script");if(o.text=e,n)for(i in v)n[i]&&(o[i]=n[i]);t.head.appendChild(o).parentNode.removeChild(o)}function x(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?l[c.call(e)]||"object":typeof e}var b="3.3.1",w=function(e,t){return new w.fn.init(e,t)},T=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;w.fn=w.prototype={jquery:"3.3.1",constructor:w,length:0,toArray:function(){return o.call(this)},get:function(e){return null==e?o.call(this):e<0?this[e+this.length]:this[e]},pushStack:function(e){var t=w.merge(this.constructor(),e);return t.prevObject=this,t},each:function(e){return w.each(this,e)},map:function(e){return this.pushStack(w.map(this,function(t,n){return e.call(t,n,t)}))},slice:function(){return this.pushStack(o.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(e){var t=this.length,n=+e+(e<0?t:0);return this.pushStack(n>=0&&n0&&t-1 in e)}var E=function(e){var t,n,r,i,o,a,s,u,l,c,f,p,d,h,g,y,v,m,x,b="sizzle"+1*new Date,w=e.document,T=0,C=0,E=ae(),k=ae(),S=ae(),D=function(e,t){return e===t&&(f=!0),0},N={}.hasOwnProperty,A=[],j=A.pop,q=A.push,L=A.push,H=A.slice,O=function(e,t){for(var n=0,r=e.length;n+~]|"+M+")"+M+"*"),z=new RegExp("="+M+"*([^\\]'\"]*?)"+M+"*\\]","g"),X=new RegExp(W),U=new RegExp("^"+R+"$"),V={ID:new RegExp("^#("+R+")"),CLASS:new RegExp("^\\.("+R+")"),TAG:new RegExp("^("+R+"|[*])"),ATTR:new RegExp("^"+I),PSEUDO:new RegExp("^"+W),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+P+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},G=/^(?:input|select|textarea|button)$/i,Y=/^h\d$/i,Q=/^[^{]+\{\s*\[native \w/,J=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,K=/[+~]/,Z=new RegExp("\\\\([\\da-f]{1,6}"+M+"?|("+M+")|.)","ig"),ee=function(e,t,n){var r="0x"+t-65536;return r!==r||n?t:r<0?String.fromCharCode(r+65536):String.fromCharCode(r>>10|55296,1023&r|56320)},te=/([\0-\x1f\x7f]|^-?\d)|^-$|[^\0-\x1f\x7f-\uFFFF\w-]/g,ne=function(e,t){return t?"\0"===e?"\ufffd":e.slice(0,-1)+"\\"+e.charCodeAt(e.length-1).toString(16)+" ":"\\"+e},re=function(){p()},ie=me(function(e){return!0===e.disabled&&("form"in e||"label"in e)},{dir:"parentNode",next:"legend"});try{L.apply(A=H.call(w.childNodes),w.childNodes),A[w.childNodes.length].nodeType}catch(e){L={apply:A.length?function(e,t){q.apply(e,H.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function oe(e,t,r,i){var o,s,l,c,f,h,v,m=t&&t.ownerDocument,T=t?t.nodeType:9;if(r=r||[],"string"!=typeof e||!e||1!==T&&9!==T&&11!==T)return r;if(!i&&((t?t.ownerDocument||t:w)!==d&&p(t),t=t||d,g)){if(11!==T&&(f=J.exec(e)))if(o=f[1]){if(9===T){if(!(l=t.getElementById(o)))return r;if(l.id===o)return r.push(l),r}else if(m&&(l=m.getElementById(o))&&x(t,l)&&l.id===o)return r.push(l),r}else{if(f[2])return L.apply(r,t.getElementsByTagName(e)),r;if((o=f[3])&&n.getElementsByClassName&&t.getElementsByClassName)return L.apply(r,t.getElementsByClassName(o)),r}if(n.qsa&&!S[e+" "]&&(!y||!y.test(e))){if(1!==T)m=t,v=e;else if("object"!==t.nodeName.toLowerCase()){(c=t.getAttribute("id"))?c=c.replace(te,ne):t.setAttribute("id",c=b),s=(h=a(e)).length;while(s--)h[s]="#"+c+" "+ve(h[s]);v=h.join(","),m=K.test(e)&&ge(t.parentNode)||t}if(v)try{return L.apply(r,m.querySelectorAll(v)),r}catch(e){}finally{c===b&&t.removeAttribute("id")}}}return u(e.replace(B,"$1"),t,r,i)}function ae(){var e=[];function t(n,i){return e.push(n+" ")>r.cacheLength&&delete t[e.shift()],t[n+" "]=i}return t}function se(e){return e[b]=!0,e}function ue(e){var t=d.createElement("fieldset");try{return!!e(t)}catch(e){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function le(e,t){var n=e.split("|"),i=n.length;while(i--)r.attrHandle[n[i]]=t}function ce(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&e.sourceIndex-t.sourceIndex;if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function fe(e){return function(t){return"input"===t.nodeName.toLowerCase()&&t.type===e}}function pe(e){return function(t){var n=t.nodeName.toLowerCase();return("input"===n||"button"===n)&&t.type===e}}function de(e){return function(t){return"form"in t?t.parentNode&&!1===t.disabled?"label"in t?"label"in t.parentNode?t.parentNode.disabled===e:t.disabled===e:t.isDisabled===e||t.isDisabled!==!e&&ie(t)===e:t.disabled===e:"label"in t&&t.disabled===e}}function he(e){return se(function(t){return t=+t,se(function(n,r){var i,o=e([],n.length,t),a=o.length;while(a--)n[i=o[a]]&&(n[i]=!(r[i]=n[i]))})})}function ge(e){return e&&"undefined"!=typeof e.getElementsByTagName&&e}n=oe.support={},o=oe.isXML=function(e){var t=e&&(e.ownerDocument||e).documentElement;return!!t&&"HTML"!==t.nodeName},p=oe.setDocument=function(e){var t,i,a=e?e.ownerDocument||e:w;return a!==d&&9===a.nodeType&&a.documentElement?(d=a,h=d.documentElement,g=!o(d),w!==d&&(i=d.defaultView)&&i.top!==i&&(i.addEventListener?i.addEventListener("unload",re,!1):i.attachEvent&&i.attachEvent("onunload",re)),n.attributes=ue(function(e){return e.className="i",!e.getAttribute("className")}),n.getElementsByTagName=ue(function(e){return e.appendChild(d.createComment("")),!e.getElementsByTagName("*").length}),n.getElementsByClassName=Q.test(d.getElementsByClassName),n.getById=ue(function(e){return h.appendChild(e).id=b,!d.getElementsByName||!d.getElementsByName(b).length}),n.getById?(r.filter.ID=function(e){var t=e.replace(Z,ee);return function(e){return e.getAttribute("id")===t}},r.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&g){var n=t.getElementById(e);return n?[n]:[]}}):(r.filter.ID=function(e){var t=e.replace(Z,ee);return function(e){var n="undefined"!=typeof e.getAttributeNode&&e.getAttributeNode("id");return n&&n.value===t}},r.find.ID=function(e,t){if("undefined"!=typeof t.getElementById&&g){var n,r,i,o=t.getElementById(e);if(o){if((n=o.getAttributeNode("id"))&&n.value===e)return[o];i=t.getElementsByName(e),r=0;while(o=i[r++])if((n=o.getAttributeNode("id"))&&n.value===e)return[o]}return[]}}),r.find.TAG=n.getElementsByTagName?function(e,t){return"undefined"!=typeof t.getElementsByTagName?t.getElementsByTagName(e):n.qsa?t.querySelectorAll(e):void 0}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},r.find.CLASS=n.getElementsByClassName&&function(e,t){if("undefined"!=typeof t.getElementsByClassName&&g)return t.getElementsByClassName(e)},v=[],y=[],(n.qsa=Q.test(d.querySelectorAll))&&(ue(function(e){h.appendChild(e).innerHTML="",e.querySelectorAll("[msallowcapture^='']").length&&y.push("[*^$]="+M+"*(?:''|\"\")"),e.querySelectorAll("[selected]").length||y.push("\\["+M+"*(?:value|"+P+")"),e.querySelectorAll("[id~="+b+"-]").length||y.push("~="),e.querySelectorAll(":checked").length||y.push(":checked"),e.querySelectorAll("a#"+b+"+*").length||y.push(".#.+[+~]")}),ue(function(e){e.innerHTML="";var t=d.createElement("input");t.setAttribute("type","hidden"),e.appendChild(t).setAttribute("name","D"),e.querySelectorAll("[name=d]").length&&y.push("name"+M+"*[*^$|!~]?="),2!==e.querySelectorAll(":enabled").length&&y.push(":enabled",":disabled"),h.appendChild(e).disabled=!0,2!==e.querySelectorAll(":disabled").length&&y.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),y.push(",.*:")})),(n.matchesSelector=Q.test(m=h.matches||h.webkitMatchesSelector||h.mozMatchesSelector||h.oMatchesSelector||h.msMatchesSelector))&&ue(function(e){n.disconnectedMatch=m.call(e,"*"),m.call(e,"[s!='']:x"),v.push("!=",W)}),y=y.length&&new RegExp(y.join("|")),v=v.length&&new RegExp(v.join("|")),t=Q.test(h.compareDocumentPosition),x=t||Q.test(h.contains)?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},D=t?function(e,t){if(e===t)return f=!0,0;var r=!e.compareDocumentPosition-!t.compareDocumentPosition;return r||(1&(r=(e.ownerDocument||e)===(t.ownerDocument||t)?e.compareDocumentPosition(t):1)||!n.sortDetached&&t.compareDocumentPosition(e)===r?e===d||e.ownerDocument===w&&x(w,e)?-1:t===d||t.ownerDocument===w&&x(w,t)?1:c?O(c,e)-O(c,t):0:4&r?-1:1)}:function(e,t){if(e===t)return f=!0,0;var n,r=0,i=e.parentNode,o=t.parentNode,a=[e],s=[t];if(!i||!o)return e===d?-1:t===d?1:i?-1:o?1:c?O(c,e)-O(c,t):0;if(i===o)return ce(e,t);n=e;while(n=n.parentNode)a.unshift(n);n=t;while(n=n.parentNode)s.unshift(n);while(a[r]===s[r])r++;return r?ce(a[r],s[r]):a[r]===w?-1:s[r]===w?1:0},d):d},oe.matches=function(e,t){return oe(e,null,null,t)},oe.matchesSelector=function(e,t){if((e.ownerDocument||e)!==d&&p(e),t=t.replace(z,"='$1']"),n.matchesSelector&&g&&!S[t+" "]&&(!v||!v.test(t))&&(!y||!y.test(t)))try{var r=m.call(e,t);if(r||n.disconnectedMatch||e.document&&11!==e.document.nodeType)return r}catch(e){}return oe(t,d,null,[e]).length>0},oe.contains=function(e,t){return(e.ownerDocument||e)!==d&&p(e),x(e,t)},oe.attr=function(e,t){(e.ownerDocument||e)!==d&&p(e);var i=r.attrHandle[t.toLowerCase()],o=i&&N.call(r.attrHandle,t.toLowerCase())?i(e,t,!g):void 0;return void 0!==o?o:n.attributes||!g?e.getAttribute(t):(o=e.getAttributeNode(t))&&o.specified?o.value:null},oe.escape=function(e){return(e+"").replace(te,ne)},oe.error=function(e){throw new Error("Syntax error, unrecognized expression: "+e)},oe.uniqueSort=function(e){var t,r=[],i=0,o=0;if(f=!n.detectDuplicates,c=!n.sortStable&&e.slice(0),e.sort(D),f){while(t=e[o++])t===e[o]&&(i=r.push(o));while(i--)e.splice(r[i],1)}return c=null,e},i=oe.getText=function(e){var t,n="",r=0,o=e.nodeType;if(o){if(1===o||9===o||11===o){if("string"==typeof e.textContent)return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=i(e)}else if(3===o||4===o)return e.nodeValue}else while(t=e[r++])n+=i(t);return n},(r=oe.selectors={cacheLength:50,createPseudo:se,match:V,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(Z,ee),e[3]=(e[3]||e[4]||e[5]||"").replace(Z,ee),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||oe.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&oe.error(e[0]),e},PSEUDO:function(e){var t,n=!e[6]&&e[2];return V.CHILD.test(e[0])?null:(e[3]?e[2]=e[4]||e[5]||"":n&&X.test(n)&&(t=a(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(Z,ee).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=E[e+" "];return t||(t=new RegExp("(^|"+M+")"+e+"("+M+"|$)"))&&E(e,function(e){return t.test("string"==typeof e.className&&e.className||"undefined"!=typeof e.getAttribute&&e.getAttribute("class")||"")})},ATTR:function(e,t,n){return function(r){var i=oe.attr(r,e);return null==i?"!="===t:!t||(i+="","="===t?i===n:"!="===t?i!==n:"^="===t?n&&0===i.indexOf(n):"*="===t?n&&i.indexOf(n)>-1:"$="===t?n&&i.slice(-n.length)===n:"~="===t?(" "+i.replace($," ")+" ").indexOf(n)>-1:"|="===t&&(i===n||i.slice(0,n.length+1)===n+"-"))}},CHILD:function(e,t,n,r,i){var o="nth"!==e.slice(0,3),a="last"!==e.slice(-4),s="of-type"===t;return 1===r&&0===i?function(e){return!!e.parentNode}:function(t,n,u){var l,c,f,p,d,h,g=o!==a?"nextSibling":"previousSibling",y=t.parentNode,v=s&&t.nodeName.toLowerCase(),m=!u&&!s,x=!1;if(y){if(o){while(g){p=t;while(p=p[g])if(s?p.nodeName.toLowerCase()===v:1===p.nodeType)return!1;h=g="only"===e&&!h&&"nextSibling"}return!0}if(h=[a?y.firstChild:y.lastChild],a&&m){x=(d=(l=(c=(f=(p=y)[b]||(p[b]={}))[p.uniqueID]||(f[p.uniqueID]={}))[e]||[])[0]===T&&l[1])&&l[2],p=d&&y.childNodes[d];while(p=++d&&p&&p[g]||(x=d=0)||h.pop())if(1===p.nodeType&&++x&&p===t){c[e]=[T,d,x];break}}else if(m&&(x=d=(l=(c=(f=(p=t)[b]||(p[b]={}))[p.uniqueID]||(f[p.uniqueID]={}))[e]||[])[0]===T&&l[1]),!1===x)while(p=++d&&p&&p[g]||(x=d=0)||h.pop())if((s?p.nodeName.toLowerCase()===v:1===p.nodeType)&&++x&&(m&&((c=(f=p[b]||(p[b]={}))[p.uniqueID]||(f[p.uniqueID]={}))[e]=[T,x]),p===t))break;return(x-=i)===r||x%r==0&&x/r>=0}}},PSEUDO:function(e,t){var n,i=r.pseudos[e]||r.setFilters[e.toLowerCase()]||oe.error("unsupported pseudo: "+e);return i[b]?i(t):i.length>1?(n=[e,e,"",t],r.setFilters.hasOwnProperty(e.toLowerCase())?se(function(e,n){var r,o=i(e,t),a=o.length;while(a--)e[r=O(e,o[a])]=!(n[r]=o[a])}):function(e){return i(e,0,n)}):i}},pseudos:{not:se(function(e){var t=[],n=[],r=s(e.replace(B,"$1"));return r[b]?se(function(e,t,n,i){var o,a=r(e,null,i,[]),s=e.length;while(s--)(o=a[s])&&(e[s]=!(t[s]=o))}):function(e,i,o){return t[0]=e,r(t,null,o,n),t[0]=null,!n.pop()}}),has:se(function(e){return function(t){return oe(e,t).length>0}}),contains:se(function(e){return e=e.replace(Z,ee),function(t){return(t.textContent||t.innerText||i(t)).indexOf(e)>-1}}),lang:se(function(e){return U.test(e||"")||oe.error("unsupported lang: "+e),e=e.replace(Z,ee).toLowerCase(),function(t){var n;do{if(n=g?t.lang:t.getAttribute("xml:lang")||t.getAttribute("lang"))return(n=n.toLowerCase())===e||0===n.indexOf(e+"-")}while((t=t.parentNode)&&1===t.nodeType);return!1}}),target:function(t){var n=e.location&&e.location.hash;return n&&n.slice(1)===t.id},root:function(e){return e===h},focus:function(e){return e===d.activeElement&&(!d.hasFocus||d.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},enabled:de(!1),disabled:de(!0),checked:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&!!e.checked||"option"===t&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,!0===e.selected},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeType<6)return!1;return!0},parent:function(e){return!r.pseudos.empty(e)},header:function(e){return Y.test(e.nodeName)},input:function(e){return G.test(e.nodeName)},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},text:function(e){var t;return"input"===e.nodeName.toLowerCase()&&"text"===e.type&&(null==(t=e.getAttribute("type"))||"text"===t.toLowerCase())},first:he(function(){return[0]}),last:he(function(e,t){return[t-1]}),eq:he(function(e,t,n){return[n<0?n+t:n]}),even:he(function(e,t){for(var n=0;n=0;)e.push(r);return e}),gt:he(function(e,t,n){for(var r=n<0?n+t:n;++r1?function(t,n,r){var i=e.length;while(i--)if(!e[i](t,n,r))return!1;return!0}:e[0]}function be(e,t,n){for(var r=0,i=t.length;r-1&&(o[l]=!(a[l]=f))}}else v=we(v===a?v.splice(h,v.length):v),i?i(null,a,v,u):L.apply(a,v)})}function Ce(e){for(var t,n,i,o=e.length,a=r.relative[e[0].type],s=a||r.relative[" "],u=a?1:0,c=me(function(e){return e===t},s,!0),f=me(function(e){return O(t,e)>-1},s,!0),p=[function(e,n,r){var i=!a&&(r||n!==l)||((t=n).nodeType?c(e,n,r):f(e,n,r));return t=null,i}];u1&&xe(p),u>1&&ve(e.slice(0,u-1).concat({value:" "===e[u-2].type?"*":""})).replace(B,"$1"),n,u0,i=e.length>0,o=function(o,a,s,u,c){var f,h,y,v=0,m="0",x=o&&[],b=[],w=l,C=o||i&&r.find.TAG("*",c),E=T+=null==w?1:Math.random()||.1,k=C.length;for(c&&(l=a===d||a||c);m!==k&&null!=(f=C[m]);m++){if(i&&f){h=0,a||f.ownerDocument===d||(p(f),s=!g);while(y=e[h++])if(y(f,a||d,s)){u.push(f);break}c&&(T=E)}n&&((f=!y&&f)&&v--,o&&x.push(f))}if(v+=m,n&&m!==v){h=0;while(y=t[h++])y(x,b,a,s);if(o){if(v>0)while(m--)x[m]||b[m]||(b[m]=j.call(u));b=we(b)}L.apply(u,b),c&&!o&&b.length>0&&v+t.length>1&&oe.uniqueSort(u)}return c&&(T=E,l=w),x};return n?se(o):o}return s=oe.compile=function(e,t){var n,r=[],i=[],o=S[e+" "];if(!o){t||(t=a(e)),n=t.length;while(n--)(o=Ce(t[n]))[b]?r.push(o):i.push(o);(o=S(e,Ee(i,r))).selector=e}return o},u=oe.select=function(e,t,n,i){var o,u,l,c,f,p="function"==typeof e&&e,d=!i&&a(e=p.selector||e);if(n=n||[],1===d.length){if((u=d[0]=d[0].slice(0)).length>2&&"ID"===(l=u[0]).type&&9===t.nodeType&&g&&r.relative[u[1].type]){if(!(t=(r.find.ID(l.matches[0].replace(Z,ee),t)||[])[0]))return n;p&&(t=t.parentNode),e=e.slice(u.shift().value.length)}o=V.needsContext.test(e)?0:u.length;while(o--){if(l=u[o],r.relative[c=l.type])break;if((f=r.find[c])&&(i=f(l.matches[0].replace(Z,ee),K.test(u[0].type)&&ge(t.parentNode)||t))){if(u.splice(o,1),!(e=i.length&&ve(u)))return L.apply(n,i),n;break}}}return(p||s(e,d))(i,t,!g,n,!t||K.test(e)&&ge(t.parentNode)||t),n},n.sortStable=b.split("").sort(D).join("")===b,n.detectDuplicates=!!f,p(),n.sortDetached=ue(function(e){return 1&e.compareDocumentPosition(d.createElement("fieldset"))}),ue(function(e){return e.innerHTML="","#"===e.firstChild.getAttribute("href")})||le("type|href|height|width",function(e,t,n){if(!n)return e.getAttribute(t,"type"===t.toLowerCase()?1:2)}),n.attributes&&ue(function(e){return e.innerHTML="",e.firstChild.setAttribute("value",""),""===e.firstChild.getAttribute("value")})||le("value",function(e,t,n){if(!n&&"input"===e.nodeName.toLowerCase())return e.defaultValue}),ue(function(e){return null==e.getAttribute("disabled")})||le(P,function(e,t,n){var r;if(!n)return!0===e[t]?t.toLowerCase():(r=e.getAttributeNode(t))&&r.specified?r.value:null}),oe}(e);w.find=E,w.expr=E.selectors,w.expr[":"]=w.expr.pseudos,w.uniqueSort=w.unique=E.uniqueSort,w.text=E.getText,w.isXMLDoc=E.isXML,w.contains=E.contains,w.escapeSelector=E.escape;var k=function(e,t,n){var r=[],i=void 0!==n;while((e=e[t])&&9!==e.nodeType)if(1===e.nodeType){if(i&&w(e).is(n))break;r.push(e)}return r},S=function(e,t){for(var n=[];e;e=e.nextSibling)1===e.nodeType&&e!==t&&n.push(e);return n},D=w.expr.match.needsContext;function N(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()}var A=/^<([a-z][^\/\0>:\x20\t\r\n\f]*)[\x20\t\r\n\f]*\/?>(?:<\/\1>|)$/i;function j(e,t,n){return g(t)?w.grep(e,function(e,r){return!!t.call(e,r,e)!==n}):t.nodeType?w.grep(e,function(e){return e===t!==n}):"string"!=typeof t?w.grep(e,function(e){return u.call(t,e)>-1!==n}):w.filter(t,e,n)}w.filter=function(e,t,n){var r=t[0];return n&&(e=":not("+e+")"),1===t.length&&1===r.nodeType?w.find.matchesSelector(r,e)?[r]:[]:w.find.matches(e,w.grep(t,function(e){return 1===e.nodeType}))},w.fn.extend({find:function(e){var t,n,r=this.length,i=this;if("string"!=typeof e)return this.pushStack(w(e).filter(function(){for(t=0;t1?w.uniqueSort(n):n},filter:function(e){return this.pushStack(j(this,e||[],!1))},not:function(e){return this.pushStack(j(this,e||[],!0))},is:function(e){return!!j(this,"string"==typeof e&&D.test(e)?w(e):e||[],!1).length}});var q,L=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/;(w.fn.init=function(e,t,n){var i,o;if(!e)return this;if(n=n||q,"string"==typeof e){if(!(i="<"===e[0]&&">"===e[e.length-1]&&e.length>=3?[null,e,null]:L.exec(e))||!i[1]&&t)return!t||t.jquery?(t||n).find(e):this.constructor(t).find(e);if(i[1]){if(t=t instanceof w?t[0]:t,w.merge(this,w.parseHTML(i[1],t&&t.nodeType?t.ownerDocument||t:r,!0)),A.test(i[1])&&w.isPlainObject(t))for(i in t)g(this[i])?this[i](t[i]):this.attr(i,t[i]);return this}return(o=r.getElementById(i[2]))&&(this[0]=o,this.length=1),this}return e.nodeType?(this[0]=e,this.length=1,this):g(e)?void 0!==n.ready?n.ready(e):e(w):w.makeArray(e,this)}).prototype=w.fn,q=w(r);var H=/^(?:parents|prev(?:Until|All))/,O={children:!0,contents:!0,next:!0,prev:!0};w.fn.extend({has:function(e){var t=w(e,this),n=t.length;return this.filter(function(){for(var e=0;e-1:1===n.nodeType&&w.find.matchesSelector(n,e))){o.push(n);break}return this.pushStack(o.length>1?w.uniqueSort(o):o)},index:function(e){return e?"string"==typeof e?u.call(w(e),this[0]):u.call(this,e.jquery?e[0]:e):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(e,t){return this.pushStack(w.uniqueSort(w.merge(this.get(),w(e,t))))},addBack:function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}});function P(e,t){while((e=e[t])&&1!==e.nodeType);return e}w.each({parent:function(e){var t=e.parentNode;return t&&11!==t.nodeType?t:null},parents:function(e){return k(e,"parentNode")},parentsUntil:function(e,t,n){return k(e,"parentNode",n)},next:function(e){return P(e,"nextSibling")},prev:function(e){return P(e,"previousSibling")},nextAll:function(e){return k(e,"nextSibling")},prevAll:function(e){return k(e,"previousSibling")},nextUntil:function(e,t,n){return k(e,"nextSibling",n)},prevUntil:function(e,t,n){return k(e,"previousSibling",n)},siblings:function(e){return S((e.parentNode||{}).firstChild,e)},children:function(e){return S(e.firstChild)},contents:function(e){return N(e,"iframe")?e.contentDocument:(N(e,"template")&&(e=e.content||e),w.merge([],e.childNodes))}},function(e,t){w.fn[e]=function(n,r){var i=w.map(this,t,n);return"Until"!==e.slice(-5)&&(r=n),r&&"string"==typeof r&&(i=w.filter(r,i)),this.length>1&&(O[e]||w.uniqueSort(i),H.test(e)&&i.reverse()),this.pushStack(i)}});var M=/[^\x20\t\r\n\f]+/g;function R(e){var t={};return w.each(e.match(M)||[],function(e,n){t[n]=!0}),t}w.Callbacks=function(e){e="string"==typeof e?R(e):w.extend({},e);var t,n,r,i,o=[],a=[],s=-1,u=function(){for(i=i||e.once,r=t=!0;a.length;s=-1){n=a.shift();while(++s-1)o.splice(n,1),n<=s&&s--}),this},has:function(e){return e?w.inArray(e,o)>-1:o.length>0},empty:function(){return o&&(o=[]),this},disable:function(){return i=a=[],o=n="",this},disabled:function(){return!o},lock:function(){return i=a=[],n||t||(o=n=""),this},locked:function(){return!!i},fireWith:function(e,n){return i||(n=[e,(n=n||[]).slice?n.slice():n],a.push(n),t||u()),this},fire:function(){return l.fireWith(this,arguments),this},fired:function(){return!!r}};return l};function I(e){return e}function W(e){throw e}function $(e,t,n,r){var i;try{e&&g(i=e.promise)?i.call(e).done(t).fail(n):e&&g(i=e.then)?i.call(e,t,n):t.apply(void 0,[e].slice(r))}catch(e){n.apply(void 0,[e])}}w.extend({Deferred:function(t){var n=[["notify","progress",w.Callbacks("memory"),w.Callbacks("memory"),2],["resolve","done",w.Callbacks("once memory"),w.Callbacks("once memory"),0,"resolved"],["reject","fail",w.Callbacks("once memory"),w.Callbacks("once memory"),1,"rejected"]],r="pending",i={state:function(){return r},always:function(){return o.done(arguments).fail(arguments),this},"catch":function(e){return i.then(null,e)},pipe:function(){var e=arguments;return w.Deferred(function(t){w.each(n,function(n,r){var i=g(e[r[4]])&&e[r[4]];o[r[1]](function(){var e=i&&i.apply(this,arguments);e&&g(e.promise)?e.promise().progress(t.notify).done(t.resolve).fail(t.reject):t[r[0]+"With"](this,i?[e]:arguments)})}),e=null}).promise()},then:function(t,r,i){var o=0;function a(t,n,r,i){return function(){var s=this,u=arguments,l=function(){var e,l;if(!(t=o&&(r!==W&&(s=void 0,u=[e]),n.rejectWith(s,u))}};t?c():(w.Deferred.getStackHook&&(c.stackTrace=w.Deferred.getStackHook()),e.setTimeout(c))}}return w.Deferred(function(e){n[0][3].add(a(0,e,g(i)?i:I,e.notifyWith)),n[1][3].add(a(0,e,g(t)?t:I)),n[2][3].add(a(0,e,g(r)?r:W))}).promise()},promise:function(e){return null!=e?w.extend(e,i):i}},o={};return w.each(n,function(e,t){var a=t[2],s=t[5];i[t[1]]=a.add,s&&a.add(function(){r=s},n[3-e][2].disable,n[3-e][3].disable,n[0][2].lock,n[0][3].lock),a.add(t[3].fire),o[t[0]]=function(){return o[t[0]+"With"](this===o?void 0:this,arguments),this},o[t[0]+"With"]=a.fireWith}),i.promise(o),t&&t.call(o,o),o},when:function(e){var t=arguments.length,n=t,r=Array(n),i=o.call(arguments),a=w.Deferred(),s=function(e){return function(n){r[e]=this,i[e]=arguments.length>1?o.call(arguments):n,--t||a.resolveWith(r,i)}};if(t<=1&&($(e,a.done(s(n)).resolve,a.reject,!t),"pending"===a.state()||g(i[n]&&i[n].then)))return a.then();while(n--)$(i[n],s(n),a.reject);return a.promise()}});var B=/^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/;w.Deferred.exceptionHook=function(t,n){e.console&&e.console.warn&&t&&B.test(t.name)&&e.console.warn("jQuery.Deferred exception: "+t.message,t.stack,n)},w.readyException=function(t){e.setTimeout(function(){throw t})};var F=w.Deferred();w.fn.ready=function(e){return F.then(e)["catch"](function(e){w.readyException(e)}),this},w.extend({isReady:!1,readyWait:1,ready:function(e){(!0===e?--w.readyWait:w.isReady)||(w.isReady=!0,!0!==e&&--w.readyWait>0||F.resolveWith(r,[w]))}}),w.ready.then=F.then;function _(){r.removeEventListener("DOMContentLoaded",_),e.removeEventListener("load",_),w.ready()}"complete"===r.readyState||"loading"!==r.readyState&&!r.documentElement.doScroll?e.setTimeout(w.ready):(r.addEventListener("DOMContentLoaded",_),e.addEventListener("load",_));var z=function(e,t,n,r,i,o,a){var s=0,u=e.length,l=null==n;if("object"===x(n)){i=!0;for(s in n)z(e,t,s,n[s],!0,o,a)}else if(void 0!==r&&(i=!0,g(r)||(a=!0),l&&(a?(t.call(e,r),t=null):(l=t,t=function(e,t,n){return l.call(w(e),n)})),t))for(;s1,null,!0)},removeData:function(e){return this.each(function(){K.remove(this,e)})}}),w.extend({queue:function(e,t,n){var r;if(e)return t=(t||"fx")+"queue",r=J.get(e,t),n&&(!r||Array.isArray(n)?r=J.access(e,t,w.makeArray(n)):r.push(n)),r||[]},dequeue:function(e,t){t=t||"fx";var n=w.queue(e,t),r=n.length,i=n.shift(),o=w._queueHooks(e,t),a=function(){w.dequeue(e,t)};"inprogress"===i&&(i=n.shift(),r--),i&&("fx"===t&&n.unshift("inprogress"),delete o.stop,i.call(e,a,o)),!r&&o&&o.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return J.get(e,n)||J.access(e,n,{empty:w.Callbacks("once memory").add(function(){J.remove(e,[t+"queue",n])})})}}),w.fn.extend({queue:function(e,t){var n=2;return"string"!=typeof e&&(t=e,e="fx",n--),arguments.length\x20\t\r\n\f]+)/i,he=/^$|^module$|\/(?:java|ecma)script/i,ge={option:[1,"",""],thead:[1,"",""],col:[2,"",""],tr:[2,"",""],td:[3,"",""],_default:[0,"",""]};ge.optgroup=ge.option,ge.tbody=ge.tfoot=ge.colgroup=ge.caption=ge.thead,ge.th=ge.td;function ye(e,t){var n;return n="undefined"!=typeof e.getElementsByTagName?e.getElementsByTagName(t||"*"):"undefined"!=typeof e.querySelectorAll?e.querySelectorAll(t||"*"):[],void 0===t||t&&N(e,t)?w.merge([e],n):n}function ve(e,t){for(var n=0,r=e.length;n-1)i&&i.push(o);else if(l=w.contains(o.ownerDocument,o),a=ye(f.appendChild(o),"script"),l&&ve(a),n){c=0;while(o=a[c++])he.test(o.type||"")&&n.push(o)}return f}!function(){var e=r.createDocumentFragment().appendChild(r.createElement("div")),t=r.createElement("input");t.setAttribute("type","radio"),t.setAttribute("checked","checked"),t.setAttribute("name","t"),e.appendChild(t),h.checkClone=e.cloneNode(!0).cloneNode(!0).lastChild.checked,e.innerHTML="x",h.noCloneChecked=!!e.cloneNode(!0).lastChild.defaultValue}();var be=r.documentElement,we=/^key/,Te=/^(?:mouse|pointer|contextmenu|drag|drop)|click/,Ce=/^([^.]*)(?:\.(.+)|)/;function Ee(){return!0}function ke(){return!1}function Se(){try{return r.activeElement}catch(e){}}function De(e,t,n,r,i,o){var a,s;if("object"==typeof t){"string"!=typeof n&&(r=r||n,n=void 0);for(s in t)De(e,s,n,r,t[s],o);return e}if(null==r&&null==i?(i=n,r=n=void 0):null==i&&("string"==typeof n?(i=r,r=void 0):(i=r,r=n,n=void 0)),!1===i)i=ke;else if(!i)return e;return 1===o&&(a=i,(i=function(e){return w().off(e),a.apply(this,arguments)}).guid=a.guid||(a.guid=w.guid++)),e.each(function(){w.event.add(this,t,i,r,n)})}w.event={global:{},add:function(e,t,n,r,i){var o,a,s,u,l,c,f,p,d,h,g,y=J.get(e);if(y){n.handler&&(n=(o=n).handler,i=o.selector),i&&w.find.matchesSelector(be,i),n.guid||(n.guid=w.guid++),(u=y.events)||(u=y.events={}),(a=y.handle)||(a=y.handle=function(t){return"undefined"!=typeof w&&w.event.triggered!==t.type?w.event.dispatch.apply(e,arguments):void 0}),l=(t=(t||"").match(M)||[""]).length;while(l--)d=g=(s=Ce.exec(t[l])||[])[1],h=(s[2]||"").split(".").sort(),d&&(f=w.event.special[d]||{},d=(i?f.delegateType:f.bindType)||d,f=w.event.special[d]||{},c=w.extend({type:d,origType:g,data:r,handler:n,guid:n.guid,selector:i,needsContext:i&&w.expr.match.needsContext.test(i),namespace:h.join(".")},o),(p=u[d])||((p=u[d]=[]).delegateCount=0,f.setup&&!1!==f.setup.call(e,r,h,a)||e.addEventListener&&e.addEventListener(d,a)),f.add&&(f.add.call(e,c),c.handler.guid||(c.handler.guid=n.guid)),i?p.splice(p.delegateCount++,0,c):p.push(c),w.event.global[d]=!0)}},remove:function(e,t,n,r,i){var o,a,s,u,l,c,f,p,d,h,g,y=J.hasData(e)&&J.get(e);if(y&&(u=y.events)){l=(t=(t||"").match(M)||[""]).length;while(l--)if(s=Ce.exec(t[l])||[],d=g=s[1],h=(s[2]||"").split(".").sort(),d){f=w.event.special[d]||{},p=u[d=(r?f.delegateType:f.bindType)||d]||[],s=s[2]&&new RegExp("(^|\\.)"+h.join("\\.(?:.*\\.|)")+"(\\.|$)"),a=o=p.length;while(o--)c=p[o],!i&&g!==c.origType||n&&n.guid!==c.guid||s&&!s.test(c.namespace)||r&&r!==c.selector&&("**"!==r||!c.selector)||(p.splice(o,1),c.selector&&p.delegateCount--,f.remove&&f.remove.call(e,c));a&&!p.length&&(f.teardown&&!1!==f.teardown.call(e,h,y.handle)||w.removeEvent(e,d,y.handle),delete u[d])}else for(d in u)w.event.remove(e,d+t[l],n,r,!0);w.isEmptyObject(u)&&J.remove(e,"handle events")}},dispatch:function(e){var t=w.event.fix(e),n,r,i,o,a,s,u=new Array(arguments.length),l=(J.get(this,"events")||{})[t.type]||[],c=w.event.special[t.type]||{};for(u[0]=t,n=1;n=1))for(;l!==this;l=l.parentNode||this)if(1===l.nodeType&&("click"!==e.type||!0!==l.disabled)){for(o=[],a={},n=0;n-1:w.find(i,this,null,[l]).length),a[i]&&o.push(r);o.length&&s.push({elem:l,handlers:o})}return l=this,u\x20\t\r\n\f]*)[^>]*)\/>/gi,Ae=/
+ +