88、检测键盘的按键

88、检测键盘的按键

脚本说明:

把如下代码加入<body>区域中

<script language="JavaScript">

<!--

var key,obj=new Object;

obj["8"]="Backspace"

obj["9"]="Tab"

obj["13"]="Enter"

//obj["16"]="Shift"

obj["17"]="Ctrl"

obj["18"]="Alt"

obj["19"]="Break"

obj["20"]="CapsLock"

obj["27"]="ESc"

obj["32"]="Space"

obj["33"]="PageUp"

obj["34"]="PageDown"

obj["35"]="End"

obj["36"]="Home"

obj["37"]="方向Left"

obj["38"]="方向Up"

obj["39"]="方向Right"

obj["40"]="方向Down"

obj["45"]="Insert"

obj["46"]="Delete"

obj["92"]="Window热键"

obj["93"]="菜单热键"

obj["144"]="NumLock"

obj["145"]="ScrollLock"

for(i=1;i<=12;i++)obj[String(111+i)]="F"+i

//for(i=0;i<=9;i++)obj[String(96+i)]="小键盘 "+i

 

function document.onkeydown(){

status=event.keyCode

if(obj[String(event.keyCode)]!=null){alert(obj[String(event.keyCode)]);event.keyCode=0;event.returnValue=false;}

}

function document.onkeypress(){

alert(String.fromCharCode(event.keyCode));

}

window.onhelp=new Function("return false;")

-->

</script>

 

Write a comment

Comments: 0