Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 11, 2025

  • Understand the issue - Control key returns VirtualKey.None on WASM instead of VirtualKey.Control
  • Identify root cause in BrowserVirtualKeyHelper.FromCode() - missing cases for "ControlLeft" and "ControlRight"
  • Add missing keyboard code mappings to BrowserVirtualKeyHelper.FromCode()
  • Create WASM-specific runtime tests for BrowserVirtualKeyHelper.FromCode()
    • Tests validate ControlLeft and ControlRight return VirtualKey.Control
    • Tests validate other modifier keys (Shift, Alt, Meta)
    • Tests validate basic keys (Space, letters, digits)
    • Tests validate unknown keys return VirtualKey.None
    • Refactored to use PlatformCondition attribute instead of #if directives
    • Wrapped entire test file with #if HAS_UNO for Uno-only compilation
    • Added comments documenting pre-existing Meta key mapping swap
  • Verify build succeeds for Uno.UWP project
  • Verify all modifier keys (Shift, Control, Alt, Meta) have Left/Right mappings
  • Code review completed
  • Security scan - no vulnerabilities detected
  • Review changes for minimalism and correctness
Original prompt

This section details on the original issue you should resolve

<issue_title>[WASM] Control key is not recognized for key events</issue_title>
<issue_description>### Current behavior 🐛

When Ctrl is pressed on keyboard and an element listens to KeyDown, it receives Key with value None instead of Control

Expected behavior 🎯

Should be Key == Control same as on other targets.

How to reproduce it (as minimally and precisely as possible) 🔬

<Page
    x:Class="UnoApp9.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:UnoApp9"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <ScrollViewer IsTabStop="True">
        <Grid>
            <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                <TextBlock
                    HorizontalAlignment="Center"
                    AutomationProperties.AutomationId="HelloTextBlock"
                    Text="Hello Uno Platform!" />
                <Button x:Name="GRD" />
            </StackPanel>
        </Grid>
    </ScrollViewer>
</Page>
public MainPage()
{
    this.InitializeComponent();

    GRD.Loaded += (s, e) =>
    {
        var a = GRD.ActualWidth;
        var b = GRD.ActualHeight;

        GRD.Focus(FocusState.Programmatic);
    };

    GRD.KeyDown += (s, e) =>
    {
        global::System.Diagnostics.Debug.WriteLine($"KeyDown: {e.Key}");
    };
}

When launched and Ctrl key is pressed on WASM, it writes "KeyDown: None" while on other targets it writes "KeyDown.Control"

Workaround 🛠️

No response

Renderer 🎨

  • Skia
  • Native

Affected platforms 📱💻🖥️

WebAssembly

Uno.Sdk version (and other relevant versions) 📦

No response

IDE version 🧑‍💻

No response

Anything else we need to know? 💬

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Fix Control key recognition in key events fix(wasm): Add Control key code mappings for keyboard events Dec 11, 2025
Copilot AI requested a review from MartinZikmund December 11, 2025 14:02
@MartinZikmund MartinZikmund marked this pull request as ready for review December 11, 2025 14:09
Copilot AI review requested due to automatic review settings December 11, 2025 14:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug on WebAssembly where pressing the Control key incorrectly returns VirtualKey.None instead of VirtualKey.Control in KeyDown events. The issue was caused by missing mappings for browser's "ControlLeft" and "ControlRight" key codes in the BrowserVirtualKeyHelper.FromCode() method.

Key Changes:

  • Added Control key mappings ("ControlLeft" and "ControlRight") to BrowserVirtualKeyHelper.FromCode()
  • Added comprehensive runtime tests validating Control, Shift, Alt, and Ctrl+A key detection on WASM/Skia platforms

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Uno.UWP/System/BrowserVirtualKeyHelper.cs Added "ControlLeft" and "ControlRight" case mappings to return VirtualKey.Control, matching existing Shift/Alt patterns
src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Input/Given_KeyRoutedEventArgs.cs New test class with 4 runtime tests for Control, Shift, Alt key presses and Ctrl+A combination

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-22104/docs/index.html

@MartinZikmund
Copy link
Member

@copilot

D:\a\1\s\src\Uno.UI.RuntimeTests\Tests\Windows_UI_Xaml_Input\Given_KeyRoutedEventArgs.cs(30,9): error CS0103: The name 'UITestHelper' does not exist in the current context [D:\a\1\s\src\Uno.UI.RuntimeTests\Uno.UI.RuntimeTests.Skia.csproj::TargetFramework=net9.0]
D:\a\1\s\src\Uno.UI.RuntimeTests\Tests\Windows_UI_Xaml_Input\Given_KeyRoutedEventArgs.cs(58,9): error CS0103: The name 'UITestHelper' does not exist in the current context [D:\a\1\s\src\Uno.UI.RuntimeTests\Uno.UI.RuntimeTests.Skia.csproj::TargetFramework=net9.0]
D:\a\1\s\src\Uno.UI.RuntimeTests\Tests\Windows_UI_Xaml_Input\Given_KeyRoutedEventArgs.cs(86,9): error CS0103: The name 'UITestHelper' does not exist in the current context [D:\a\1\s\src\Uno.UI.RuntimeTests\Uno.UI.RuntimeTests.Skia.csproj::TargetFramework=net9.0]
D:\a\1\s\src\Uno.UI.RuntimeTests\Tests\Windows_UI_Xaml_Input\Given_KeyRoutedEventArgs.cs(113,26): error CS1061: 'KeyRoutedEventArgs' does not contain a definition for 'KeyModifiers' and no accessible extension method 'KeyModifiers' accepting a first argument of type 'KeyRoutedEventArgs' could be found (are you missing a using directive or an assembly reference?) [D:\a\1\s\src\Uno.UI.RuntimeTests\Uno.UI.RuntimeTests.Skia.csproj::TargetFramework=net9.0]
D:\a\1\s\src\Uno.UI.RuntimeTests\Tests\Windows_UI_Xaml_Input\Given_KeyRoutedEventArgs.cs(117,9): error CS0103: The name 'UITestHelper' does not exist in the current context [D:\a\1\s\src\Uno.UI.RuntimeTests\Uno.UI.RuntimeTests.Skia.csproj::TargetFramework=net9.0]
D:\a\1\s\src\Uno.UI.RuntimeTests\Tests\Windows_UI_Xaml_Input\Given_KeyRoutedEventArgs.cs(127,108): error IDE0055: Fix formatting (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0055) [D:\a\1\s\src\Uno.UI.RuntimeTests\Uno.UI.RuntimeTests.Skia.csproj::TargetFramework=net9.0]

Copy link
Contributor Author

Copilot AI commented Dec 16, 2025

@copilot

D:\a\1\s\src\Uno.UI.RuntimeTests\Tests\Windows_UI_Xaml_Input\Given_KeyRoutedEventArgs.cs(30,9): error CS0103: The name 'UITestHelper' does not exist in the current context [D:\a\1\s\src\U...

Fixed all build errors in commit a113841:

  • Added missing using Uno.UI.RuntimeTests.Helpers; directive to resolve UITestHelper errors
  • Changed e.KeyModifiers to e.KeyboardModifiers (correct property name)
  • Fixed formatting on the multi-line Assert statement

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-22104/docs/index.html

@unodevops
Copy link
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22104/wasm-skia-net9/index.html

@MartinZikmund MartinZikmund force-pushed the copilot/fix-control-key-event branch from a113841 to b04e8cc Compare December 18, 2025 15:36
@MartinZikmund MartinZikmund force-pushed the copilot/fix-control-key-event branch from b04e8cc to f276f86 Compare December 18, 2025 15:37
@MartinZikmund
Copy link
Member

@copilot can you create a test that validates the return value for Ctrl key on BrowserVirtualKeyHelper.cs via a WASM-specific runtime test?

Copy link
Contributor Author

Copilot AI commented Dec 18, 2025

@copilot can you create a test that validates the return value for Ctrl key on BrowserVirtualKeyHelper.cs via a WASM-specific runtime test?

Created WASM-specific runtime test in commit 252ecc6. The test validates BrowserVirtualKeyHelper.FromCode() directly with 11 test methods covering:

  • ControlLeft/ControlRight → VirtualKey.Control (the main fix)
  • ShiftLeft/ShiftRight → VirtualKey.Shift
  • AltLeft/AltRight → VirtualKey.Menu
  • MetaLeft/MetaRight → Windows keys
  • Space, KeyA, Digit0 → basic key mappings
  • Unknown keys → VirtualKey.None

All tests are wrapped in #if __WASM__ to run only on WebAssembly.

@unodevops
Copy link
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22104/wasm-skia-net9/index.html

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-22104/docs/index.html

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-22104/docs/index.html

@unodevops
Copy link
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22104/wasm-skia-net9/index.html

auto-merge was automatically disabled December 18, 2025 18:57

Head branch was pushed to by a user without write access

Copilot AI requested a review from MartinZikmund December 18, 2025 19:04
@unodevops
Copy link
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-22104/wasm-skia-net9/index.html

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-22104/docs/index.html

@unodevops
Copy link
Contributor

⚠️⚠️ The build 189084 has failed on Uno.UI - CI.

@MartinZikmund MartinZikmund merged commit 46dc4a2 into master Dec 18, 2025
53 checks passed
@MartinZikmund MartinZikmund deleted the copilot/fix-control-key-event branch December 18, 2025 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[WASM] Control key is not recognized for key events

5 participants