利用JavaScript实现键盘监控。代码如下(把地址设置成自己的机器,并监听相应端口就可以了)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>键盘监控</title>
</head>
<body>
<input type="text" id="12580" />
</body>
<script type="text/javascript">
window.onload = function () {
var character = document.getElementById("12580");
document.onkeydown = function (event) {
event = event || window.event;/*||为或语句,当IE不能识别event时候,就执行window.event 赋值*/
console.log(event.key);
switch (event.key){/*key:键盘输入的数*/
case 'a':
document.getElementById("12580").style.background="url(http://127.0.0.1:6556/a)"
break;
case 'b':
document.getElementById("12580").style.background="url(http://127.0.0.1:6556/b)"
break;
case 'c':
document.getElementById("12580").style.background="url(http//:127.0.0.1:6556/c)"
break;
case '1':
document.getElementById("12580").style.background="url(http://127.0.0.1:6556/1)"
break;
}
}
}
</script>
</html>