キーボードのキーを押してください。


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<meta http-equiv="Content-Style-Type" content="text/css">
<title>キーボードを操作した時に処理したい</title>
<script type="text/JavaScript">
<!--
function keydisp(e) {
if (navigator.appName == "Netscape") {
alert ("ブラウザはNetscape関連です。\n文字コード = "+e.which+"\n押されたキー = "+String.fromCharCode(e.which));
} else {
alert ("ブラウザはInternet Explorer関連です。\n文字コード = "+ window.event.keyCode+"\n押されたキー = "+String.fromCharCode(event.keyCode));
}
}
document.onkeydown = keydisp;
// -->
</script>
</head>
<body>
<p>キーボードのキーを押してください。</p>
</body>
</html>


★解説★