Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
```
17 changes: 9 additions & 8 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)'
Expand All @@ -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'
Expand All @@ -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/')))
Expand All @@ -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
5 changes: 5 additions & 0 deletions src/GregsStack.InputSimulatorStandard/IMouseSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public interface IMouseSimulator
/// </summary>
int MouseWheelClickSize { get; set; }

/// <summary>
/// Retrieves the position of the mouse cursor, in screen coordinates.
/// </summary>
System.Drawing.Point Position { get; }

/// <summary>
/// Simulates mouse movement by the specified distance measured as a delta from the current mouse location in pixels.
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions src/GregsStack.InputSimulatorStandard/MouseSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ internal MouseSimulator(IInputMessageDispatcher messageDispatcher)
/// </summary>
public int MouseWheelClickSize { get; set; } = 120;

/// <inheritdoc />
/// <summary>
/// Retrieves the position of the mouse cursor, in screen coordinates.
/// </summary>
public System.Drawing.Point Position
{
get
{
NativeMethods.GetCursorPos(out Point lpPoint);
return lpPoint;
}
}

/// <inheritdoc />
/// <summary>
/// Simulates mouse movement by the specified distance measured as a delta from the current mouse location in pixels.
Expand Down
8 changes: 8 additions & 0 deletions src/GregsStack.InputSimulatorStandard/Native/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,13 @@ internal static class NativeMethods
/// <returns></returns>
[DllImport("user32.dll")]
public static extern uint MapVirtualKey(uint uCode, uint uMapType);

/// <summary>
/// Retrieves the cursor's position, in screen coordinates.
/// </summary>
/// <param name="lpPoint">A pointer to a <see cref="Point" /> structure that receives the screen coordinates of the cursor.</param>
/// <returns>Returns <c>true</c> if successful or <c>false</c> otherwise.</returns>
[DllImport("user32.dll", SetLastError = true)]
public static extern bool GetCursorPos(out Point lpPoint);
}
}
23 changes: 23 additions & 0 deletions src/GregsStack.InputSimulatorStandard/Native/Point.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace GregsStack.InputSimulatorStandard.Native
{
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential)]
internal struct Point
{
/// <summary>
/// Gets or sets the x-coordinate of this Point.
/// </summary>
public int X { get; set; }

/// <summary>
/// Gets or sets the y-coordinate of this Point.
/// </summary>
public int Y { get; set; }

public static implicit operator System.Drawing.Point(Point point)
{
return new System.Drawing.Point(point.X, point.Y);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="altcover" Version="5.3.688" />
<PackageReference Include="altcover" Version="6.1.708" />
<PackageReference Include="HtmlAgilityPack" Version="1.11.12" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="Moq" Version="4.12.0" />
<PackageReference Include="Moq" Version="4.13.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,15 @@ public void NullMessageDispatcherThrowsInvalidOperationException()
Assert.Throws<InvalidOperationException>(() => this.mouseSimulator = new MouseSimulator(null));
}
}

public class PositionProperty : MouseSimulatorTests
{
[Fact]
public void GetPosition()
{
var position = this.mouseSimulator.Position;
Assert.False(position.IsEmpty);
}
}
}
}
2 changes: 1 addition & 1 deletion tools/NuGet.Tools/NuGet.Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Codecov" Version="1.7.1" />
<PackageReference Include="Codecov" Version="1.7.2" />
</ItemGroup>

</Project>