mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
Intorduce Page.keyboard (#74)
Introduce page.keyboard to provide low-level access to the keyboard.
This commit is contained in:
committed by
Andrey Lushnikov
parent
895f69d17a
commit
bf7698e8f8
44
test/assets/input/keyboard.html
Normal file
44
test/assets/input/keyboard.html
Normal file
@@ -0,0 +1,44 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Keyboard test</title>
|
||||
</head>
|
||||
<body>
|
||||
<textarea></textarea>
|
||||
<script>
|
||||
window.result = "";
|
||||
let textarea = document.querySelector('textarea');
|
||||
textarea.focus();
|
||||
textarea.addEventListener('keydown', event => {
|
||||
log('Keydown:', event.key, event.which, modifiers(event));
|
||||
});
|
||||
textarea.addEventListener('keypress', event => {
|
||||
log('Keypress:', event.key, event.which, event.keyCode, event.charCode, modifiers(event));
|
||||
});
|
||||
textarea.addEventListener('keyup', event => {
|
||||
log('Keyup:', event.key, event.which, modifiers(event));
|
||||
});
|
||||
function modifiers(event) {
|
||||
let m = [];
|
||||
if (event.altKey)
|
||||
m.push('Alt')
|
||||
if (event.ctrlKey)
|
||||
m.push('Control');
|
||||
if (event.metaKey)
|
||||
m.push('Meta')
|
||||
if (event.shiftKey)
|
||||
m.push('Shift')
|
||||
return '[' + m.join(' ') + ']';
|
||||
}
|
||||
function log(...args) {
|
||||
console.log.apply(console, args);
|
||||
result += args.join(' ') + '\n';
|
||||
}
|
||||
function getResult() {
|
||||
let temp = result.trim();
|
||||
result = "";
|
||||
return temp;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user