<html>
<meta http
equiv=
Content
Type
content=
text/html; charset=gb
>
<head>
<script language=
javascript
>
var ie =navigator
appName==
Microsoft Internet Explorer
?true:false;
function keyDown(e)
{
if(!ie)
{
var nkey=e
which;
var iekey=
現在是ns浏覽器
;
var realkey=String
fromCharCode(e
which);
}
if(ie)
{
var iekey=event
keyCode;
var nkey=
現在是ie浏覽器
;
var realkey=String
fromCharCode(event
keyCode);
if(event
keyCode==
){realkey=
\
空格\
}
if(event
keyCode==
){realkey=
\
回車\
}
if(event
keyCode==
){realkey=
\
Esc\
}
if(event
keyCode==
){realkey=
\
Shift\
}
if(event
keyCode==
){realkey=
\
Ctrl\
}
if(event
keyCode==
){realkey=
\
Alt\
}
}
alert(
ns浏覽器中鍵值:
+nkey+
\n
+
ie浏覽器中鍵值:
+iekey+
\n
+
實際鍵為
+realkey);
}
document
onkeydown = keyDown;
</script>
</head>
<body>
//Javascript Document
<hr>
<center>
<h
>請按任意一個鍵
</h
>
</center>
</body>
</html>
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19587.html