<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button id="btn">123</button>
<div id="info">1234</div>
<script>
var btn = document.querySelector('#btn')
var info = document.querySelector('#info')
document.addEventListener('keydown', function (e) {
// 获取键盘的ascill码
btn.innerHTML = e.keyCode
// 获取ascill在键盘上对应的字符
var charStr = String.fromCharCode(e.keyCode);
info.innerHTML = charStr
})
</script>
</body>
</html>
https://www.jianshu.com/p/7b75427c62be
https://blog.csdn.net/iteye_12432/article/details/82357820
https://www.cnblogs.com/weiqinl/p/10575727.html
https://www.cnblogs.com/lf6112/archive/2013/02/17/2914368.html