2017-07-18 01:49:52 +00:00
|
|
|
<!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 => {
|
2017-10-12 01:09:43 +00:00
|
|
|
log('Keydown:', event.key, event.code, event.which, modifiers(event));
|
2017-07-18 01:49:52 +00:00
|
|
|
});
|
|
|
|
textarea.addEventListener('keypress', event => {
|
2019-02-06 21:49:14 +00:00
|
|
|
log('Keypress:', event.key, event.code, event.which, event.charCode, modifiers(event));
|
2017-07-18 01:49:52 +00:00
|
|
|
});
|
|
|
|
textarea.addEventListener('keyup', event => {
|
2017-10-12 01:09:43 +00:00
|
|
|
log('Keyup:', event.key, event.code, event.which, modifiers(event));
|
2017-07-18 01:49:52 +00:00
|
|
|
});
|
|
|
|
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>
|