Skip to content

Commit

Permalink
Press Key issue with combined keys #67
Browse files Browse the repository at this point in the history
Keyboard input example implemented
  • Loading branch information
Nepitwin committed May 18, 2022
1 parent 427a512 commit d71d325
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 10 deletions.
6 changes: 3 additions & 3 deletions TestApplications/src/Notifier/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>
</configuration>
3 changes: 2 additions & 1 deletion TestApplications/src/Notifier/Notifier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
<OutputType>WinExe</OutputType>
<RootNamespace>NotifierTest</RootNamespace>
<AssemblyName>Notifier</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion TestApplications/src/WpfApplication/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>
11 changes: 11 additions & 0 deletions TestApplications/src/WpfApplication/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
mc:Ignorable="d"
Title="FlaUI WPF Test App"
Height="533.931" Width="629.303"
KeyDown="OnKeyDown"
KeyUp="OnKeyUp"
ResizeMode="CanResize">
<Window.Resources>
<ResourceDictionary>
Expand Down Expand Up @@ -177,6 +179,15 @@
</StackPanel>
</ScrollViewer>
</TabItem>
<TabItem Header="Keyboard Controls">
<StackPanel Orientation="Vertical">
<Button x:Name="ResetKeyboard" Content="Reset Keyboard Inputs" Click="ResetKeyboard_Click" AutomationProperties.AutomationId="ResetKeyboardInputs"/>
<Label Content="Keyboard Down Events"/>
<Label Content="" Foreground="White" Background="Black" x:Name="lblKeyboardKeyDown"/>
<Label Content="Keyboard Up Events"/>
<Label Content="" Foreground="White" Background="Black" x:Name="lblKeyboardKeyUp"/>
</StackPanel>
</TabItem>
</TabControl>
</DockPanel>
</Window>
Expand Down
45 changes: 45 additions & 0 deletions TestApplications/src/WpfApplication/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Collections.Generic;

namespace WpfApplication
{
Expand All @@ -8,6 +10,10 @@ namespace WpfApplication
/// </summary>
public partial class MainWindow
{
private List<Key> _keysUp = new List<Key>();
private List<Key> _keysDown = new List<Key>();


public MainWindow()
{
InitializeComponent();
Expand Down Expand Up @@ -41,5 +47,44 @@ private void OnShowLabel(object sender, RoutedEventArgs e)
lblMenuChk.Visibility = Visibility.Hidden;
}
}

private void OnKeyDown(object sender, KeyEventArgs e)
{
_keysDown.Add(e.Key);
lblKeyboardKeyDown.Content = GenerateKeyboardOutput(_keysDown);
}

private void OnKeyUp(object sender, KeyEventArgs e)
{
_keysUp.Add(e.Key);
lblKeyboardKeyUp.Content = GenerateKeyboardOutput(_keysUp);
}

private string GenerateKeyboardOutput(List<Key> keys)
{
var output = "";

for (int i = 0; i < keys.Count; i++)
{
if (i == keys.Count - 1)
{
output += keys[i];
}
else
{
output += keys[i] + "+";
}
}

return output;
}

private void ResetKeyboard_Click(object sender, RoutedEventArgs e)
{
_keysDown.Clear();
_keysUp.Clear();
lblKeyboardKeyDown.Content = GenerateKeyboardOutput(_keysDown);
lblKeyboardKeyUp.Content = GenerateKeyboardOutput(_keysUp);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion TestApplications/src/WpfApplication/WpfApplication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WpfApplication</RootNamespace>
<AssemblyName>WpfApplication</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
Expand Down

0 comments on commit d71d325

Please sign in to comment.