OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <!-- | |
3 The html/js to help testing keyboard events. It | |
4 - receives keybord events and preventDefault(), | |
5 - writes the key codes to /html/body/div[@id='container'], | |
6 - sends the key codes to window.domAutomationController once KeyX is received. | |
7 --> | |
8 <html> | |
9 <head> | |
10 <title>Fullscreen Keyboard Lock Test</title> | |
11 <script> | |
12 let done = false; | |
13 function getKeyEventReport() { | |
14 return new Promise((resolve, reject) => { | |
15 const register = () => { | |
16 window.setTimeout(() => { | |
Paweł Hajdan Jr.
2017/07/11 11:59:57
What's the purpose of this delay? Looks like a pol
Hzj_jie
2017/07/11 17:47:26
The key events are sent to renderer process throug
Hzj_jie
2017/07/12 02:41:06
But yes, this logic is over-complex, I have update
| |
17 if (done) { | |
18 resolve(); | |
19 } else { | |
20 register(); | |
21 } | |
22 }, 100); | |
23 }; | |
24 register(); | |
25 }).then(() => { | |
26 window.domAutomationController.send(container().innerHTML); | |
27 }); | |
28 }; | |
29 | |
30 function isMacOSFullscreenShortcut(e) { | |
31 return e.metaKey && | |
32 e.ctrlKey && | |
33 !e.altKey && | |
34 !e.shiftKey && | |
35 e.code == "KeyF"; | |
36 } | |
37 | |
38 function isF11FullscreenShortcut(e) { | |
39 return !e.metaKey && | |
40 !e.ctrlKey && | |
41 !e.altKey && | |
42 !e.shiftKey && | |
43 e.code == "F11"; | |
44 } | |
45 | |
46 function isBrowserFullscreenShortcut(e) { | |
47 return isMacOSFullscreenShortcut(e) || | |
48 isF11FullscreenShortcut(e); | |
49 } | |
50 | |
51 function container() { | |
52 return document.getElementById('container'); | |
53 } | |
54 | |
55 function consumeEvent(type, e) { | |
56 if (type == 'keydown' && | |
57 !e.code.startsWith("Control") && | |
58 !e.code.startsWith("Shift") && | |
59 !e.code.startsWith("Alt") && | |
60 !e.code.startsWith("Meta")) { | |
61 container().innerHTML += | |
62 e.code + | |
63 ' ctrl:' + e.getModifierState('Control') + | |
64 ' shift:' + e.getModifierState('Shift') + | |
65 ' alt:' + e.getModifierState('Alt') + | |
66 ' meta:' + e.getModifierState('Meta') + '\n'; | |
67 } | |
68 e.preventDefault(); | |
69 } | |
70 | |
71 function init() { | |
72 document.addEventListener('keydown', (e) => { | |
73 // The web content triggers fullscreen on the "S" key down event. | |
74 if (e.code == 'KeyS') { | |
75 container().webkitRequestFullscreen(); | |
76 } else if (isBrowserFullscreenShortcut(e)) { | |
77 // Web page can consume fullscreen shortcut when the page is in | |
78 // window mode, but it's not expected in test cases. | |
79 return; | |
80 } | |
81 consumeEvent('keydown', e); | |
82 }); | |
83 | |
84 document.addEventListener('keyup', (e) => { | |
85 if (isBrowserFullscreenShortcut(e)) { | |
86 return; | |
87 } | |
88 consumeEvent('keyup', e); | |
89 | |
90 if (e.code == 'KeyX') { | |
91 done = true; | |
92 } | |
93 }); | |
94 | |
95 document.addEventListener('keypress', (e) => { | |
96 consumeEvent('keypress', e); | |
97 }); | |
98 } | |
99 </script> | |
100 </head> | |
101 <body onload='init()'> | |
102 <div id='container'> | |
103 </div> | |
104 </body> | |
105 </html> | |
OLD | NEW |