logseq/e2e-tests/util/keyboard-events.ts

466 lines
9.0 KiB
TypeScript
Raw Normal View History

2022-03-30 17:34:18 +00:00
/***
* Author: Junyi Du <junyi@logseq.com>
* References:
* https://stackoverflow.com/questions/8892238/detect-keyboard-layout-with-javascript
* ***/
import { Page } from '@playwright/test'
interface RecordedEvent {
event_type: string;
event: any; // KeyboardEvent is too heavy
latency: number;
}
export let dispatch_kb_events = async function (page: Page, selector: string, keyboard_events: RecordedEvent[] ){
for (let kbev of keyboard_events){
let { event_type, event, latency } = kbev
await page.waitForTimeout(latency)
await page.dispatchEvent(selector, event_type, event)
}
}
export let macos_pinyin_left_full_square_bracket: RecordedEvent[] = [
{
"event_type": "keydown",
"event": {
"key": "【",
"code": "BracketLeft",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": false
},
"latency": 0
},
{
"event_type": "keypress",
"event": {
"key": "【",
"code": "BracketLeft",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
"isComposing": false
},
"latency": 1
},
{
"event_type": "keyup",
"event": {
"key": "【",
"code": "BracketLeft",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": false
},
"latency": 17
}
2022-03-07 12:08:38 +00:00
]
export let win10_pinyin_left_full_square_bracket: RecordedEvent[] = [
2022-03-07 12:08:38 +00:00
{
"event_type": "keydown",
"event": {
"key": "Process",
"code": "BracketLeft",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": false
},
"latency": 0
},
{
"event_type": "compositionstart",
"event": {},
"latency": 4
},
{
"event_type": "compositionupdate",
"event": {},
"latency": 0
},
{
"event_type": "compositionupdate",
"event": {},
"latency": 12
},
{
"event_type": "compositionend",
"event": {},
"latency": 1
2022-03-07 12:08:38 +00:00
},
{
"event_type": "keyup",
"event": {
"key": "Process",
"code": "BracketLeft",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": false
},
"latency": 61
2022-03-07 12:08:38 +00:00
},
{
"event_type": "keyup",
"event": {
"key": "[",
"code": "BracketLeft",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": false
},
"latency": 1
2022-03-07 12:08:38 +00:00
}
]
export let win10_legacy_pinyin_left_full_square_bracket: RecordedEvent[] = [
2022-03-07 12:08:38 +00:00
{
"event_type": "keydown",
"event": {
"key": "Process",
"code": "BracketLeft",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": false
},
"latency": 0
},
{
"event_type": "compositionstart",
"event": {},
"latency": 1
},
{
"event_type": "compositionupdate",
"event": {},
"latency": 0
},
{
"event_type": "compositionupdate",
"event": {},
"latency": 0
},
{
"event_type": "compositionend",
"event": {},
"latency": 1
2022-03-07 12:08:38 +00:00
},
{
"event_type": "keyup",
"event": {
"key": "Process",
"code": "BracketLeft",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": false
},
"latency": 93
2022-03-07 12:08:38 +00:00
}
]
export let macos_pinyin_selecting_candidate_double_left_square_bracket: RecordedEvent[] = [
2022-03-07 12:08:38 +00:00
{
"event_type": "keydown",
"event": {
2022-03-07 18:16:55 +00:00
"key": "b",
"code": "KeyB",
2022-03-07 12:08:38 +00:00
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": false
},
"latency": 0
},
{
"event_type": "compositionstart",
"event": {},
"latency": 1
},
{
"event_type": "compositionupdate",
"event": {},
"latency": 0
2022-03-07 12:08:38 +00:00
},
{
"event_type": "keyup",
"event": {
2022-03-07 18:16:55 +00:00
"key": "b",
"code": "KeyB",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": true
},
"latency": 48
2022-03-07 18:16:55 +00:00
},
{
"event_type": "keydown",
"event": {
"key": "】",
"code": "BracketRight",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": true
},
"latency": 627
2022-03-07 18:16:55 +00:00
},
{
"event_type": "keyup",
"event": {
"key": "】",
"code": "BracketRight",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": true
},
"latency": 59
2022-03-07 18:16:55 +00:00
},
{
"event_type": "keydown",
"event": {
"key": "】",
"code": "BracketRight",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": true
},
"latency": 289
2022-03-07 18:16:55 +00:00
},
{
"event_type": "keyup",
"event": {
"key": "】",
"code": "BracketRight",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": true
},
"latency": 73
2022-03-07 18:16:55 +00:00
},
{
"event_type": "keydown",
"event": {
"key": "【",
"code": "BracketLeft",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": true
},
"latency": 443
2022-03-07 18:16:55 +00:00
},
{
"event_type": "keyup",
"event": {
"key": "【",
"code": "BracketLeft",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": true
},
"latency": 79
},
{
"event_type": "keydown",
"event": {
"key": "【",
2022-03-07 12:08:38 +00:00
"code": "BracketLeft",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": true
},
"latency": 155
2022-03-07 12:08:38 +00:00
},
{
"event_type": "keyup",
"event": {
"key": "【",
2022-03-07 12:08:38 +00:00
"code": "BracketLeft",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": true
},
"latency": 44
},
{
"event_type": "compositionend",
"event": {},
"latency": 968
}
]
export let win10_RIME_selecting_candidate_double_left_square_bracket: RecordedEvent[] = [
{
"event_type": "keydown",
"event": {
"key": "Process",
2022-03-30 17:34:18 +00:00
"code": "BracketRight",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": false
},
"latency": 0
},
{
2022-03-30 17:34:18 +00:00
"event_type": "compositionstart",
"event": {},
"latency": 0
},
{
2022-03-30 17:34:18 +00:00
"event_type": "compositionupdate",
"event": {},
"latency": 0
2022-03-07 18:16:55 +00:00
},
{
"event_type": "keyup",
"event": {
"key": "Process",
"code": "BracketRight",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": true
},
"latency": 79
2022-03-07 18:16:55 +00:00
},
{
"event_type": "keyup",
"event": {
"key": "]",
"code": "BracketRight",
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": true
},
"latency": 3
2022-03-07 18:16:55 +00:00
},
2022-03-07 12:08:38 +00:00
{
"event_type": "keydown",
"event": {
"key": "Process",
2022-03-30 17:34:18 +00:00
"code": "BracketRight",
2022-03-07 12:08:38 +00:00
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": true
},
"latency": 237
2022-03-07 12:08:38 +00:00
},
{
"event_type": "keyup",
"event": {
"key": "Process",
2022-03-30 17:34:18 +00:00
"code": "BracketRight",
2022-03-07 12:08:38 +00:00
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": true
},
"latency": 96
2022-03-07 12:08:38 +00:00
},
{
"event_type": "keyup",
"event": {
2022-03-30 17:34:18 +00:00
"key": "]",
"code": "BracketRight",
2022-03-07 12:08:38 +00:00
"location": 0,
"ctrlKey": false,
"shiftKey": false,
"altKey": false,
"metaKey": false,
"repeat": false,
2022-03-30 17:34:18 +00:00
"isComposing": true
},
"latency": 3
2022-03-07 12:08:38 +00:00
},
{
2022-03-30 17:34:18 +00:00
"event_type": "compositionend",
"event": {},
"latency": 1479
2022-03-07 12:08:38 +00:00
}
]