diff --git a/MouseKeyHook.sln b/MouseKeyHook.sln index c9df0e9..9eb1cb1 100644 --- a/MouseKeyHook.sln +++ b/MouseKeyHook.sln @@ -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 @@ -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 diff --git a/TestNet48Windows/SingleKeyPressTest.cs b/TestNet48Windows/SingleKeyPressTest.cs new file mode 100644 index 0000000..9aaefb5 --- /dev/null +++ b/TestNet48Windows/SingleKeyPressTest.cs @@ -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 channel; + private AutoResetEvent handle; + private string buffer; + + [SetUp] + public void Setup() + { + channel = Channel.CreateUnbounded(); + 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); + } + } +} \ No newline at end of file diff --git a/TestNet48Windows/TestNet48Windows.csproj b/TestNet48Windows/TestNet48Windows.csproj new file mode 100644 index 0000000..a1a71e2 --- /dev/null +++ b/TestNet48Windows/TestNet48Windows.csproj @@ -0,0 +1,26 @@ + + + + net48 + + false + + x86 + + + + + + + + + + + + + + + + + +