From ba29e2615cc13bb345618e3ed0c8e766a21ff830 Mon Sep 17 00:00:00 2001 From: Gregor Sindl Date: Sun, 1 Sep 2019 20:15:59 +0200 Subject: [PATCH 1/5] Update azure-pipelines.yml --- azure-pipelines.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 25f2fce..d3df9be 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -65,12 +65,13 @@ steps: - powershell: | $testsDirectory = Join-Path -Path '$(Build.SourcesDirectory)' -ChildPath 'tests' $coverageFile = Get-ChildItem -Path "$testsDirectory" -Recurse -File -Filter 'coverage.xml' | Select-Object -First 1 - & "$ENV:USERPROFILE\.nuget\packages\codecov\1.7.1\tools\codecov.exe" -f "$($coverageFile.FullName)" -t '$(CODECOV_TOKEN)' + $codecovExecutable = Get-ChildItem -Path "$ENV:USERPROFILE\.nuget\packages\codecov" -Recurse -File -Filter "codecov.exe" | Sort-Object -Descending -Property FullName | Select-Object -First 1 + & "$($codecovExecutable.FullName)" -f "$($coverageFile.FullName)" -t '$(CODECOV_TOKEN)' displayName: 'Upload coverage to codecov.io' - task: DotNetCoreCLI@2 displayName: 'Pack projects' - condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'))) + condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), eq(variables['Build.SourceBranch'], 'refs/heads/develop'), startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'))) inputs: command: 'pack' packagesToPack: '$(Solution)' @@ -80,14 +81,14 @@ steps: versionEnvVar: 'GITVERSION_NUGETVERSIONV2' - task: NuGetToolInstaller@1 - condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'))) + condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), eq(variables['Build.SourceBranch'], 'refs/heads/develop'), startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'))) inputs: versionSpec: '5.1.0' checkLatest: true - task: NuGetCommand@2 displayName: 'Push *.nupkg and *.snupkg to nuget.org' - condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'))) + condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), eq(variables['Build.SourceBranch'], 'refs/heads/develop'), startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'))) inputs: command: 'push' packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg' @@ -103,8 +104,8 @@ steps: action: 'create' target: '$(Build.SourceVersion)' tagSource: 'manual' - tag: '$(Build.BuildNumber)' - title: '$(Build.BuildNumber)' + tag: 'v$(Build.BuildNumber)' + title: 'v$(Build.BuildNumber)' - task: GitHubRelease@0 condition: and(succeeded(), or(eq(variables['Build.SourceBranch'], 'refs/heads/develop'), startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'))) @@ -114,6 +115,6 @@ steps: action: 'create' target: '$(Build.SourceVersion)' tagSource: 'manual' - tag: '$(Build.BuildNumber)' - title: '$(Build.BuildNumber)' + tag: 'v$(Build.BuildNumber)' + title: 'v$(Build.BuildNumber)' isPreRelease: true From 93bd2a8774018848cd917cb8998a6188c6791f21 Mon Sep 17 00:00:00 2001 From: Gregor Sindl Date: Sun, 1 Sep 2019 21:05:24 +0200 Subject: [PATCH 2/5] Get current mouse position Resolves #5 --- .../IMouseSimulator.cs | 5 ++++ .../MouseSimulator.cs | 13 +++++++++++ .../Native/NativeMethods.cs | 8 +++++++ .../Native/Point.cs | 23 +++++++++++++++++++ .../MouseSimulatorTests.cs | 10 ++++++++ 5 files changed, 59 insertions(+) create mode 100644 src/GregsStack.InputSimulatorStandard/Native/Point.cs diff --git a/src/GregsStack.InputSimulatorStandard/IMouseSimulator.cs b/src/GregsStack.InputSimulatorStandard/IMouseSimulator.cs index 5204368..fe19f0d 100644 --- a/src/GregsStack.InputSimulatorStandard/IMouseSimulator.cs +++ b/src/GregsStack.InputSimulatorStandard/IMouseSimulator.cs @@ -12,6 +12,11 @@ public interface IMouseSimulator /// int MouseWheelClickSize { get; set; } + /// + /// Retrieves the position of the mouse cursor, in screen coordinates. + /// + System.Drawing.Point Position { get; } + /// /// Simulates mouse movement by the specified distance measured as a delta from the current mouse location in pixels. /// diff --git a/src/GregsStack.InputSimulatorStandard/MouseSimulator.cs b/src/GregsStack.InputSimulatorStandard/MouseSimulator.cs index 0db466c..5135886 100644 --- a/src/GregsStack.InputSimulatorStandard/MouseSimulator.cs +++ b/src/GregsStack.InputSimulatorStandard/MouseSimulator.cs @@ -43,6 +43,19 @@ internal MouseSimulator(IInputMessageDispatcher messageDispatcher) /// public int MouseWheelClickSize { get; set; } = 120; + /// + /// + /// Retrieves the position of the mouse cursor, in screen coordinates. + /// + public System.Drawing.Point Position + { + get + { + NativeMethods.GetCursorPos(out Point lpPoint); + return lpPoint; + } + } + /// /// /// Simulates mouse movement by the specified distance measured as a delta from the current mouse location in pixels. diff --git a/src/GregsStack.InputSimulatorStandard/Native/NativeMethods.cs b/src/GregsStack.InputSimulatorStandard/Native/NativeMethods.cs index 84c1737..b06f86e 100644 --- a/src/GregsStack.InputSimulatorStandard/Native/NativeMethods.cs +++ b/src/GregsStack.InputSimulatorStandard/Native/NativeMethods.cs @@ -106,5 +106,13 @@ internal static class NativeMethods /// [DllImport("user32.dll")] public static extern uint MapVirtualKey(uint uCode, uint uMapType); + + /// + /// Retrieves the cursor's position, in screen coordinates. + /// + /// A pointer to a structure that receives the screen coordinates of the cursor. + /// Returns true if successful or false otherwise. + [DllImport("user32.dll", SetLastError = true)] + public static extern bool GetCursorPos(out Point lpPoint); } } diff --git a/src/GregsStack.InputSimulatorStandard/Native/Point.cs b/src/GregsStack.InputSimulatorStandard/Native/Point.cs new file mode 100644 index 0000000..1cc1dd0 --- /dev/null +++ b/src/GregsStack.InputSimulatorStandard/Native/Point.cs @@ -0,0 +1,23 @@ +namespace GregsStack.InputSimulatorStandard.Native +{ + using System.Runtime.InteropServices; + + [StructLayout(LayoutKind.Sequential)] + internal struct Point + { + /// + /// Gets or sets the x-coordinate of this Point. + /// + public int X { get; set; } + + /// + /// Gets or sets the y-coordinate of this Point. + /// + public int Y { get; set; } + + public static implicit operator System.Drawing.Point(Point point) + { + return new System.Drawing.Point(point.X, point.Y); + } + } +} diff --git a/tests/GregsStack.InputSimulatorStandard.Tests/MouseSimulatorTests.cs b/tests/GregsStack.InputSimulatorStandard.Tests/MouseSimulatorTests.cs index d41992f..6523eee 100644 --- a/tests/GregsStack.InputSimulatorStandard.Tests/MouseSimulatorTests.cs +++ b/tests/GregsStack.InputSimulatorStandard.Tests/MouseSimulatorTests.cs @@ -23,5 +23,15 @@ public void NullMessageDispatcherThrowsInvalidOperationException() Assert.Throws(() => this.mouseSimulator = new MouseSimulator(null)); } } + + public class PositionProperty : MouseSimulatorTests + { + [Fact] + public void GetPosition() + { + var position = this.mouseSimulator.Position; + Assert.False(position.IsEmpty); + } + } } } From a4ae1a32b8098334239676df0029733cc2f91b7f Mon Sep 17 00:00:00 2001 From: Gregor Sindl Date: Sun, 1 Sep 2019 21:06:00 +0200 Subject: [PATCH 3/5] Update Codecov --- tools/NuGet.Tools/NuGet.Tools.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/NuGet.Tools/NuGet.Tools.csproj b/tools/NuGet.Tools/NuGet.Tools.csproj index d882577..3b1973a 100644 --- a/tools/NuGet.Tools/NuGet.Tools.csproj +++ b/tools/NuGet.Tools/NuGet.Tools.csproj @@ -6,7 +6,7 @@ - + From 623c05f3b207315d3e2c99e0ca44fef6924e907c Mon Sep 17 00:00:00 2001 From: Gregor Sindl Date: Sun, 1 Sep 2019 21:08:07 +0200 Subject: [PATCH 4/5] Update altcover and Moq --- .../GregsStack.InputSimulatorStandard.Tests.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/GregsStack.InputSimulatorStandard.Tests/GregsStack.InputSimulatorStandard.Tests.csproj b/tests/GregsStack.InputSimulatorStandard.Tests/GregsStack.InputSimulatorStandard.Tests.csproj index ebd689e..6bc12db 100644 --- a/tests/GregsStack.InputSimulatorStandard.Tests/GregsStack.InputSimulatorStandard.Tests.csproj +++ b/tests/GregsStack.InputSimulatorStandard.Tests/GregsStack.InputSimulatorStandard.Tests.csproj @@ -6,10 +6,10 @@ - + - + all From 0c74b1f5098e3c940283c0c71185006de18efd92 Mon Sep 17 00:00:00 2001 From: Gregor Sindl Date: Sun, 1 Sep 2019 21:37:27 +0200 Subject: [PATCH 5/5] Extend Readme.md --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index f137354..527efaf 100644 --- a/README.md +++ b/README.md @@ -86,3 +86,14 @@ public void GetKeyStatus() var isCapsLockOn = simulator.InputDeviceState.IsTogglingKeyInEffect(VirtualKeyCode.CAPITAL); } ``` + +## Example: Get current mouse position +```csharp +public void GetMousePosition() +{ + var simulator = new InputSimulator(); + + // Gets the mouse position as System.Drawing.Point + var position = simulator.Mouse.Position; +} +```