Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vNexz -> master #180

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
10 changes: 8 additions & 2 deletions MouseKeyHook.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FormsExample", "examples\Fo
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleHook", "examples\ConsoleHook\ConsoleHook.csproj", "{490FBC6C-B347-4C33-B8EF-5C67C7C4C884}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestNet48Windows", "TestNet48Windows\TestNet48Windows.csproj", "{EF95F236-A4CC-4A68-B656-7C02355D0C3E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -38,17 +40,21 @@ Global
{F52AA97E-180A-40ED-8F2B-09080171D6C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F52AA97E-180A-40ED-8F2B-09080171D6C7}.Release|Any CPU.Build.0 = Release|Any CPU
{9754749C-1EEA-4468-8C32-B5BAC3235F54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9754749C-1EEA-4468-8C32-B5BAC3235F54}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9754749C-1EEA-4468-8C32-B5BAC3235F54}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F9B78F1A-F065-4BB4-A15B-393DFFE8DB0B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F9B78F1A-F065-4BB4-A15B-393DFFE8DB0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F9B78F1A-F065-4BB4-A15B-393DFFE8DB0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{693C8A54-2FA1-408B-9896-7CB1E5E9E257}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{693C8A54-2FA1-408B-9896-7CB1E5E9E257}.Debug|Any CPU.Build.0 = Debug|Any CPU
{693C8A54-2FA1-408B-9896-7CB1E5E9E257}.Release|Any CPU.ActiveCfg = Release|Any CPU
{693C8A54-2FA1-408B-9896-7CB1E5E9E257}.Release|Any CPU.Build.0 = Release|Any CPU
{490FBC6C-B347-4C33-B8EF-5C67C7C4C884}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{490FBC6C-B347-4C33-B8EF-5C67C7C4C884}.Debug|Any CPU.Build.0 = Debug|Any CPU
{490FBC6C-B347-4C33-B8EF-5C67C7C4C884}.Release|Any CPU.ActiveCfg = Release|Any CPU
{490FBC6C-B347-4C33-B8EF-5C67C7C4C884}.Release|Any CPU.Build.0 = Release|Any CPU
{EF95F236-A4CC-4A68-B656-7C02355D0C3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EF95F236-A4CC-4A68-B656-7C02355D0C3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EF95F236-A4CC-4A68-B656-7C02355D0C3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EF95F236-A4CC-4A68-B656-7C02355D0C3E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
65 changes: 65 additions & 0 deletions TestNet48Windows/SingleKeyPressTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Diagnostics.Tracing;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using System.Windows.Forms;
using Gma.System.MouseKeyHook;
using NUnit.Framework;

namespace UnitTestWindows
{


public class SingleKeyPressTest
{

private Channel<KeyPressEventArgs> channel;
private AutoResetEvent handle;
private string buffer;

[SetUp]
public void Setup()
{
channel = Channel.CreateUnbounded<KeyPressEventArgs>();
Hook.GlobalEvents().KeyPress += OnKeyPress;
handle = new AutoResetEvent(false);
buffer= string.Empty;
}

private void OnKeyPress(object sender, KeyPressEventArgs e)
{
//var canWrite = channel.Writer.TryWrite(e);
//Assert.True(canWrite);
System.Console.WriteLine(e.KeyChar);
e.Handled = true;
buffer += e.KeyChar;
handle.Reset();
}

[TearDown]
public void TearDown()
{
Hook.GlobalEvents().KeyPress -= OnKeyPress;
this.channel.Writer.Complete();
}

[Test]
public void TestAllRegularKeystrokes()
{
var expected = "abcdefghijklmnopqrstuvwxyz1234567890`-=[]\\;',./";

// Simulate keystrokes for all regular and special keys
foreach (var key in expected)
{
handle.Set();
// Send the keystroke using SendKeys.SendWait
SendKeys.SendWait("{" + key + "}");
Application.DoEvents();
handle.WaitOne(100);
}
var actual = buffer;
Assert.AreEqual(expected, actual);
}
}
}
26 changes: 26 additions & 0 deletions TestNet48Windows/TestNet48Windows.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>

<IsPackable>false</IsPackable>

<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="System.Threading.Channels" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\examples\ConsoleHook\ConsoleHook.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="System.Windows.Forms" />
</ItemGroup>

</Project>