JavaScript 鍵盤控制事件
JavaScript 鍵盤控制事件(Web模式下即時判斷鍵盤的狀態)
Key Codes對照表: Key Codes.htm
鍵盤控制事件<script type="text/javascript">
function ChkKey
{
kc=event.keyCode;
if(kc==13)
{
alert("您所輸入的按鍵為Enter");
}
}
</script>
<body>
<input type="text" id="KeyEvent" name="KeyEvent" value="" onkeypress="CheckMO();" />
</body>
複合鍵的判斷 <script>
function getKeyValue() {
s1.innerHTML = "";
if (event.shiftKey && event.keyCode != 16)
s1.innerHTML = "Shift一起被按下";
else if (event.ctrlKey && event.keyCode != 17)
s1.innerHTML = "Ctrl一起被按下";
else if (event.altKey && event.keyCode != 18)
s1.innerHTML = "Alt一起被按下";
s2.innerHTML = "鍵值 = " + event.keyCode;
}
document.body.onkeydown = getKeyValue;
</script>
Key Codes對照表: Key Codes.htm
鍵盤控制事件<script type="text/javascript">
function ChkKey
{
kc=event.keyCode;
if(kc==13)
{
alert("您所輸入的按鍵為Enter");
}
}
</script>
<body>
<input type="text" id="KeyEvent" name="KeyEvent" value="" onkeypress="CheckMO();" />
</body>
複合鍵的判斷 <script>
function getKeyValue() {
s1.innerHTML = "";
if (event.shiftKey && event.keyCode != 16)
s1.innerHTML = "Shift一起被按下";
else if (event.ctrlKey && event.keyCode != 17)
s1.innerHTML = "Ctrl一起被按下";
else if (event.altKey && event.keyCode != 18)
s1.innerHTML = "Alt一起被按下";
s2.innerHTML = "鍵值 = " + event.keyCode;
}
document.body.onkeydown = getKeyValue;
</script>
留言
張貼留言