Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/web_ui/lib/src/engine/keyboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class Keyboard {
'keymap': 'web',
'code': keyboardEvent.code,
'key': keyboardEvent.key,
'location': keyboardEvent.location,
'metaState': _lastMetaState,
};

Expand All @@ -151,6 +152,7 @@ class Keyboard {
'keymap': 'web',
'code': event.code,
'key': event.key,
'location': event.location,
'metaState': _lastMetaState,
};

Expand Down
38 changes: 36 additions & 2 deletions lib/web_ui/test/keyboard_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void testMain() {
'type': 'keyup',
'keymap': 'web',
'code': 'SomeCode',
'location': 0,
'key': 'SomeKey',
'metaState': 0x0,
});
Expand Down Expand Up @@ -92,6 +93,7 @@ void testMain() {
'keymap': 'web',
'code': 'SomeCode',
'key': 'SomeKey',
'location': 0,
'metaState': 0x0,
});
expect(event.defaultPrevented, isFalse);
Expand Down Expand Up @@ -124,6 +126,7 @@ void testMain() {
'keymap': 'web',
'code': 'SomeCode',
'key': 'SomeKey',
'location': 0,
// ctrl
'metaState': 0x4,
});
Expand All @@ -142,6 +145,7 @@ void testMain() {
'keymap': 'web',
'code': 'SomeCode',
'key': 'SomeKey',
'location': 0,
// shift alt meta
'metaState': 0x1 | 0x2 | 0x8,
});
Expand Down Expand Up @@ -191,6 +195,7 @@ void testMain() {
'keymap': 'web',
'code': 'SomeCode',
'key': 'SomeKey',
'location': 0,
'metaState': 0,
};
expect(messages, <Map<String, dynamic>>[
Expand Down Expand Up @@ -346,12 +351,14 @@ void testMain() {
'keydown',
key: 'Meta',
code: 'MetaLeft',
location: 1,
isMetaPressed: true,
);
dispatchKeyboardEvent(
'keydown',
key: 'Alt',
code: 'AltLeft',
location: 1,
isMetaPressed: true,
isAltPressed: true,
);
Expand All @@ -367,9 +374,15 @@ void testMain() {
'keyup',
key: 'Meta',
code: 'MetaLeft',
location: 1,
isAltPressed: true,
);
dispatchKeyboardEvent('keyup', key: 'Alt', code: 'AltLeft');
dispatchKeyboardEvent(
'keyup',
key: 'Alt',
code: 'AltLeft',
location: 1,
);
// Notice no `keyup` for "i".

expect(messages, <Map<String, dynamic>>[
Expand All @@ -378,6 +391,7 @@ void testMain() {
'keymap': 'web',
'key': 'Meta',
'code': 'MetaLeft',
'location': 1,
// meta
'metaState': 0x8,
},
Expand All @@ -386,6 +400,7 @@ void testMain() {
'keymap': 'web',
'key': 'Alt',
'code': 'AltLeft',
'location': 1,
// alt meta
'metaState': 0x2 | 0x8,
},
Expand All @@ -394,6 +409,7 @@ void testMain() {
'keymap': 'web',
'key': 'i',
'code': 'KeyI',
'location': 0,
// alt meta
'metaState': 0x2 | 0x8,
},
Expand All @@ -402,6 +418,7 @@ void testMain() {
'keymap': 'web',
'key': 'Meta',
'code': 'MetaLeft',
'location': 1,
// alt
'metaState': 0x2,
},
Expand All @@ -410,6 +427,7 @@ void testMain() {
'keymap': 'web',
'key': 'Alt',
'code': 'AltLeft',
'location': 1,
'metaState': 0x0,
},
]);
Expand All @@ -426,6 +444,7 @@ void testMain() {
'keymap': 'web',
'key': 'i',
'code': 'KeyI',
'location': 0,
'metaState': 0x0,
}
]);
Expand All @@ -449,12 +468,14 @@ void testMain() {
'keydown',
key: 'Meta',
code: 'MetaLeft',
location: 1,
isMetaPressed: true,
);
dispatchKeyboardEvent(
'keydown',
key: 'Alt',
code: 'AltLeft',
location: 1,
isMetaPressed: true,
isAltPressed: true,
);
Expand All @@ -470,9 +491,15 @@ void testMain() {
'keyup',
key: 'Meta',
code: 'MetaLeft',
location: 1,
isAltPressed: true,
);
dispatchKeyboardEvent('keyup', key: 'Alt', code: 'AltLeft');
dispatchKeyboardEvent(
'keyup',
key: 'Alt',
code: 'AltLeft',
location: 1,
);
// Notice no `keyup` for "i".

messages.clear();
Expand All @@ -497,6 +524,7 @@ void testMain() {
'keymap': 'web',
'key': 'i',
'code': 'KeyI',
'location': 0,
'metaState': 0x0,
});
}
Expand Down Expand Up @@ -551,12 +579,14 @@ void testMain() {
'keydown',
key: 'Meta',
code: 'MetaLeft',
location: 1,
isMetaPressed: true,
);
dispatchKeyboardEvent(
'keydown',
key: 'Alt',
code: 'AltLeft',
location: 1,
isMetaPressed: true,
isAltPressed: true,
);
Expand All @@ -572,6 +602,7 @@ void testMain() {
'keyup',
key: 'Meta',
code: 'MetaLeft',
location: 1,
isAltPressed: true,
);
// Notice no `keyup` for "AltLeft" and "i".
Expand All @@ -587,6 +618,7 @@ void testMain() {
'keymap': 'web',
'key': 'i',
'code': 'KeyI',
'location': 0,
// alt
'metaState': 0x2,
}
Expand Down Expand Up @@ -616,6 +648,7 @@ html.KeyboardEvent dispatchKeyboardEvent(
html.EventTarget? target,
String? key,
String? code,
int location = 0,
bool repeat = false,
bool isShiftPressed = false,
bool isAltPressed = false,
Expand All @@ -631,6 +664,7 @@ html.KeyboardEvent dispatchKeyboardEvent(
<String, dynamic>{
'key': key,
'code': code,
'location': location,
'repeat': repeat,
'shiftKey': isShiftPressed,
'altKey': isAltPressed,
Expand Down