Skip to content

Commit

Permalink
test: add a manual test for wasm keyboard tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed Nov 7, 2024
1 parent 542a226 commit ae1d7c5
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -4254,6 +4254,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Input\Keyboard\Keyboard_Modifiers.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Input\Keyboard\Keyboard_iOS_Theme.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -8185,6 +8189,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Input\Keyboard\Keyboard_Events.xaml.cs">
<DependentUpon>Keyboard_Events.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Input\Keyboard\Keyboard_Modifiers.xaml.cs">
<DependentUpon>Keyboard_Modifiers.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Input\Keyboard\Keyboard_iOS_Theme.xaml.cs">
<DependentUpon>Keyboard_iOS_Theme.xaml</DependentUpon>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Page
x:Class="UITests.Windows_UI_Xaml_Input.Keyboard.Keyboard_Modifiers"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Windows_UI_Xaml_Input.Keyboard"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<StackPanel>
<TextBlock>
<Run Text="Repro steps (only Uno targets, not WinUI):" />
<LineBreak />
<Run Text="1. You should see 'Modifiers pressed: None' below." />
<LineBreak />
<Run Text="2. Press the Shift key. You should see the modifier status below change to reflect that shift is pressed" />
<LineBreak />
<Run Text="3. Release the Shift key. You should see tha modifier status below go back to 'Modifiers pressed: None'" />
</TextBlock>
<TextBlock x:Name="statusTb" Text="Modifiers pressed: None" />
</StackPanel>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Linq;
using Windows.System;
using Windows.UI.Core;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Uno.UI.Samples.Controls;

namespace UITests.Windows_UI_Xaml_Input.Keyboard
{
[Sample("Keyboard", IsManualTest = true)]
public sealed partial class Keyboard_Modifiers : Page
{
private DispatcherTimer _timer;

public Keyboard_Modifiers()
{
this.InitializeComponent();
#if HAS_UNO
_timer = new DispatcherTimer();
_timer.Interval = TimeSpan.FromMilliseconds(100);
_timer.Tick += (_, _) =>
{
var mods = PlatformHelpers.GetKeyboardModifiers();
var modString = "";
if (mods.HasFlag(VirtualKeyModifiers.Shift))
{
modString += " Shift";
}
if (mods.HasFlag(VirtualKeyModifiers.Control))
{
modString += " Ctrl";
}
if (mods.HasFlag(VirtualKeyModifiers.Windows))
{
modString += " Win";
}
if (mods.HasFlag(VirtualKeyModifiers.Menu))
{
modString += " Menu";
}

if (string.IsNullOrEmpty(modString))
{
modString = "None";
}
statusTb.Text = $"Modifiers pressed: {modString}";
};

Loaded += (_, _) => _timer.Start();
Unloaded += (_, _) => _timer.Stop();
#endif
}
}
}

0 comments on commit ae1d7c5

Please sign in to comment.