diff --git a/Tests/LibWeb/Text/expected/UIEvents/KeyEvent-non-ascii.txt b/Tests/LibWeb/Text/expected/UIEvents/KeyEvent-non-ascii.txt
new file mode 100644
index 00000000000..72ec9c1971a
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/UIEvents/KeyEvent-non-ascii.txt
@@ -0,0 +1,6 @@
+keydown à
+keydown á
+keydown â
+keydown ã
+keydown ä
+keydown å
diff --git a/Tests/LibWeb/Text/input/UIEvents/KeyEvent-non-ascii.html b/Tests/LibWeb/Text/input/UIEvents/KeyEvent-non-ascii.html
new file mode 100644
index 00000000000..69bbf48e136
--- /dev/null
+++ b/Tests/LibWeb/Text/input/UIEvents/KeyEvent-non-ascii.html
@@ -0,0 +1,18 @@
+
+
+
diff --git a/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.cpp b/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.cpp
index a8ff1cbdc56..98e49be8499 100644
--- a/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.cpp
+++ b/Userland/Libraries/LibWeb/UIEvents/KeyboardEvent.cpp
@@ -272,18 +272,22 @@ static ErrorOr get_event_key(KeyCode platform_key, u32 code_point)
{
// 1. Let key be a DOMString initially set to "Unidentified".
// NOTE: We return "Unidentified" at the end to avoid needlessly allocating it here.
- Optional key;
// 2. If there exists an appropriate named key attribute value for this key event, then
- if (auto named_key = TRY(get_event_named_key(platform_key)); named_key.has_value()) {
- // 1. Set key to that named key attribute value.
- key = named_key.release_value();
+ // AD-HOC: Key_Invalid would be interpreted as "Unidentified" here. But we also use Key_Invalid for key presses that
+ // are not on a standard US keyboard. If such a key would generate a valid key string below, let's allow that
+ // to happen; otherwise, we will still return "Unidentified" at the end.
+ if (platform_key != KeyCode::Key_Invalid) {
+ if (auto named_key = TRY(get_event_named_key(platform_key)); named_key.has_value()) {
+ // 1. Set key to that named key attribute value.
+ return named_key.release_value();
+ }
}
// 3. Else, if the key event generates a valid key string, then
- else if (auto key_string = TRY(get_event_key_string(code_point)); key_string.has_value()) {
+ if (auto key_string = TRY(get_event_key_string(code_point)); key_string.has_value()) {
// 1. Set key to that key string value.
- key = key_string.release_value();
+ return key_string.release_value();
}
// FIXME: 4. Else, if the key event has any modifier keys other than glyph modifier keys, then
@@ -291,8 +295,6 @@ static ErrorOr get_event_key(KeyCode platform_key, u32 code_point)
// modifer keys removed except for glyph modifier keys.
// 5. Return key as the key attribute value for this key event.
- if (key.has_value())
- return key.release_value();
return "Unidentified"_string;
}