-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
825 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.28307.168 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeyTest", "KeyTest\KeyTest.csproj", "{6F06FAF0-1DF9-4C44-A766-27C6CCACEFB0}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{6F06FAF0-1DF9-4C44-A766-27C6CCACEFB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{6F06FAF0-1DF9-4C44-A766-27C6CCACEFB0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{6F06FAF0-1DF9-4C44-A766-27C6CCACEFB0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{6F06FAF0-1DF9-4C44-A766-27C6CCACEFB0}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {5345CCDE-32F7-4E56-9AA5-4CC6E365BA5C} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Application x:Class="KeyTest.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="clr-namespace:KeyTest" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
|
||
namespace KeyTest | ||
{ | ||
/// <summary> | ||
/// Interaktionslogik für "App.xaml" | ||
/// </summary> | ||
public partial class App : Application | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{6F06FAF0-1DF9-4C44-A766-27C6CCACEFB0}</ProjectGuid> | ||
<OutputType>WinExe</OutputType> | ||
<RootNamespace>KeyTest</RootNamespace> | ||
<AssemblyName>KeyTest</AssemblyName> | ||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<WarningLevel>4</WarningLevel> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<Deterministic>true</Deterministic> | ||
<PublishUrl>publish\</PublishUrl> | ||
<Install>true</Install> | ||
<InstallFrom>Disk</InstallFrom> | ||
<UpdateEnabled>false</UpdateEnabled> | ||
<UpdateMode>Foreground</UpdateMode> | ||
<UpdateInterval>7</UpdateInterval> | ||
<UpdateIntervalUnits>Days</UpdateIntervalUnits> | ||
<UpdatePeriodically>false</UpdatePeriodically> | ||
<UpdateRequired>false</UpdateRequired> | ||
<MapFileExtensions>true</MapFileExtensions> | ||
<ApplicationRevision>0</ApplicationRevision> | ||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> | ||
<IsWebBootstrapper>false</IsWebBootstrapper> | ||
<UseApplicationTrust>false</UseApplicationTrust> | ||
<BootstrapperEnabled>true</BootstrapperEnabled> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<LangVersion>7.3</LangVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<ApplicationIcon>Ressources\KeyTest.ico</ApplicationIcon> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xaml"> | ||
<RequiredTargetFramework>4.0</RequiredTargetFramework> | ||
</Reference> | ||
<Reference Include="WindowsBase" /> | ||
<Reference Include="PresentationCore" /> | ||
<Reference Include="PresentationFramework" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ApplicationDefinition Include="App.xaml"> | ||
<Generator>MSBuild:Compile</Generator> | ||
<SubType>Designer</SubType> | ||
</ApplicationDefinition> | ||
<Compile Include="Windows\Kernel32.cs" /> | ||
<Compile Include="Windows\KeyboardHock.cs" /> | ||
<Compile Include="Windows\User32.cs" /> | ||
<Page Include="MainWindow.xaml"> | ||
<Generator>MSBuild:Compile</Generator> | ||
<SubType>Designer</SubType> | ||
</Page> | ||
<Compile Include="App.xaml.cs"> | ||
<DependentUpon>App.xaml</DependentUpon> | ||
<SubType>Code</SubType> | ||
</Compile> | ||
<Compile Include="MainWindow.xaml.cs"> | ||
<DependentUpon>MainWindow.xaml</DependentUpon> | ||
<SubType>Code</SubType> | ||
</Compile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Properties\AssemblyInfo.cs"> | ||
<SubType>Code</SubType> | ||
</Compile> | ||
<Compile Include="Properties\Resources.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DesignTime>True</DesignTime> | ||
<DependentUpon>Resources.resx</DependentUpon> | ||
</Compile> | ||
<Compile Include="Properties\Settings.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>Settings.settings</DependentUpon> | ||
<DesignTimeSharedInput>True</DesignTimeSharedInput> | ||
</Compile> | ||
<EmbeddedResource Include="Properties\Resources.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | ||
</EmbeddedResource> | ||
<None Include="Properties\Settings.settings"> | ||
<Generator>SettingsSingleFileGenerator</Generator> | ||
<LastGenOutput>Settings.Designer.cs</LastGenOutput> | ||
</None> | ||
<None Include="Ressources\KeyTest.xcf" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<BootstrapperPackage Include=".NETFramework,Version=v4.6.2"> | ||
<Visible>False</Visible> | ||
<ProductName>Microsoft .NET Framework 4.6.2 %28x86 und x64%29</ProductName> | ||
<Install>true</Install> | ||
</BootstrapperPackage> | ||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> | ||
<Visible>False</Visible> | ||
<ProductName>.NET Framework 3.5 SP1</ProductName> | ||
<Install>false</Install> | ||
</BootstrapperPackage> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Resource Include="Ressources\KeyTest.ico" /> | ||
<Resource Include="Ressources\KeyTest_x1024.png" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Window x:Class="KeyTest.MainWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:local="clr-namespace:KeyTest" | ||
mc:Ignorable="d" | ||
Title="KeyTest" Height="300" Width="400" MinWidth="240" MinHeight="130"> | ||
<Grid> | ||
<ScrollViewer x:Name="OutScroll" Margin="15,15,15,50" VerticalScrollBarVisibility="Auto"> | ||
<TextBlock x:Name="Output" Text="" FontSize="20" FontFamily="Segoe UI Semibold" TextWrapping="Wrap"/> | ||
</ScrollViewer> | ||
<TextBlock x:Name="CenterInfo" Margin="15,15,15,50" Text="PRESS ANY KEY" VerticalAlignment="Center" HorizontalAlignment="Center" Opacity="0.5" FontSize="20" Visibility="Visible" FontFamily="Segoe WP SemiLight"/> | ||
<Button x:Name="ClearButton" Content="Clear" HorizontalAlignment="Left" Margin="15,0,0,15" VerticalAlignment="Bottom" FontFamily="Segoe UI Light" Width="90" Click="ClearButton_Click"/> | ||
<Label x:Name="CountText" Content="Key Count: " HorizontalAlignment="Left" Margin="115,0,0,12" VerticalAlignment="Bottom" Opacity="0.6" Width="70" FontFamily="Segoe UI Semibold"/> | ||
<Label x:Name="CountInfo" Content="0" Margin="185,0,15,12" Opacity="0.6" VerticalAlignment="Bottom" FontFamily="Segoe UI Semibold"/> | ||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
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; | ||
using KeyTest.Windows; | ||
|
||
namespace KeyTest | ||
{ | ||
/// <summary> | ||
/// Interaktionslogik für MainWindow.xaml | ||
/// </summary> | ||
public partial class MainWindow : Window | ||
{ | ||
|
||
public int KeyCount { get; private set; } | ||
|
||
|
||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
|
||
var ver = Assembly.GetExecutingAssembly().GetName().Version; | ||
this.Title += $" - v{ver.Major}.{ver.Minor}"; | ||
|
||
KeyboardHock.Initialize(); | ||
KeyboardHock.KeyEvent += KeyEvent; | ||
} | ||
|
||
private void HandleKey(KeyInfo info) | ||
{ | ||
Run txt = null; | ||
Run meta = null; | ||
if (info.Position < 0) | ||
{ | ||
info.Position = Output.Inlines.Count; | ||
|
||
txt = new Run(info.KeyString); | ||
meta = new Run(""); | ||
Output.Inlines.Add(txt); // text | ||
Output.Inlines.Add(meta); // meta info | ||
Output.Inlines.Add(new Run(" ")); // spaceing | ||
} | ||
else | ||
{ | ||
txt = (Run)Output.Inlines.ElementAt(info.Position); | ||
meta = (Run)txt.NextInline; | ||
} | ||
|
||
meta.Text = $"{info.Timer.ElapsedMilliseconds}ms"; | ||
meta.FontSize = Output.FontSize * 0.5; | ||
|
||
if (info.KeyDown) | ||
{ | ||
if (info.Event.IsSysKey) txt.Foreground = new SolidColorBrush(Color.FromRgb(40, 120, 240)); | ||
else txt.Foreground = new SolidColorBrush(Color.FromRgb(240, 40, 40)); | ||
meta.Foreground = new SolidColorBrush(Color.FromRgb(100, 100, 100)); | ||
} | ||
if (info.KeyUp) | ||
{ | ||
txt.Foreground = new SolidColorBrush(Color.FromRgb(100, 100, 100)); | ||
meta.Foreground = new SolidColorBrush(Color.FromRgb(180, 180, 180)); | ||
} | ||
|
||
OutScroll.ScrollToEnd(); | ||
} | ||
|
||
private void KeyEvent(object sender, KeyHockEventArgs e) | ||
{ | ||
if (CenterInfo.IsVisible) CenterInfo.Visibility = Visibility.Hidden; | ||
|
||
var last = KeyInfo.Set(e); | ||
if (last.KeyUp) HandleKey(last); | ||
|
||
foreach (var info in KeyInfo.EventList.Values) | ||
{ | ||
HandleKey(info); | ||
} | ||
|
||
KeyCount++; | ||
CountInfo.Content = KeyCount; | ||
} | ||
|
||
private void ClearButton_Click(object sender, RoutedEventArgs e) | ||
{ | ||
KeyInfo.EventList.Clear(); | ||
Output.Text = ""; | ||
CenterInfo.Visibility = Visibility.Visible; | ||
KeyCount = 0; | ||
} | ||
} | ||
|
||
public class KeyInfo | ||
{ | ||
public static Dictionary<int, KeyInfo> EventList { get; } = new Dictionary<int, KeyInfo>(); | ||
|
||
public KeyHockEventArgs Event { get; private set; } | ||
public Stopwatch Timer { get; } = new Stopwatch(); | ||
public int Position { get; set; } = -1; | ||
|
||
|
||
private KeyInfo(KeyHockEventArgs @event) | ||
{ | ||
Event = @event; | ||
} | ||
|
||
public int VirtualKey => Event.VirtualKey; | ||
public bool KeyDown => Event.KeyDown; | ||
public bool KeyUp => Event.KeyUp; | ||
public bool IsUnknow => Event.IsUnknow; | ||
|
||
public string KeyString => Event.Key.ToString(); | ||
|
||
|
||
public static KeyInfo Set(KeyHockEventArgs @event) | ||
{ | ||
if (!EventList.TryGetValue(@event.VirtualKey, out var info)) | ||
{ | ||
info = new KeyInfo(@event); | ||
if (info.KeyDown) EventList.Add(@event.VirtualKey, info); | ||
} | ||
else | ||
{ | ||
info.Event = @event; | ||
} | ||
|
||
if (info.KeyDown) info.Timer.Start(); | ||
if (info.KeyUp) | ||
{ | ||
info.Timer.Stop(); | ||
EventList.Remove(info.VirtualKey); | ||
} | ||
|
||
return info; | ||
} | ||
|
||
} | ||
} | ||
|
Oops, something went wrong.