Friday, January 14, 2005

 

Capture Keydown Message in IE

这个还是以前讨论的IE相关问题,有人提起,所以又翻出来啦。

1.
IE下按键捕捉最方便的方法是在HTML文件中插入脚本(script),比如起点中文网的翻书script代码是

[code]
script language=javascript>
document.onkeydown=nextpage
function nextpage() {
if (event.keyCode==13) location="showbook.asp?bl_id=7776"

if (event.keyCode==37) location="readchapter.asp?Bu_id=197591&bl_id=7776"

if (event.keyCode==39) location="readchapter.asp?Bu_id=199758&bl_id=7776"
}
[/code]

又比如孙展波兄提到的捕获F1按键
From http://blog.joycode.com/zhanbos/archive/2004/03/10/15537.aspx

[code]
html>
head>
title>Demo: Capture F1/title>
script language="jscript">
// generic function to handle ALL onkeydown events
document.onkeydown = trapKeys;
// will cancel the default F1 functionality in IE
window.onhelp = new Function("return false;");
function trapKeys()
{
var nKey = window.event.keyCode;
switch(parseInt(nKey))
{
// F1
case 112:
div1.innerHTML = "帮助在此";
break;
//Other keys
default:
div1.innerHTML = "演示结束";
break;
}
}
/script>
/head>
body>
div id="div1" style="FONT-WEIGHT: bold; FONT-SIZE: 18px; COLOR: blue">
按任何键继续。寻求帮助按F1
/div>
/body>
/html>
[/cdoe]

方便吧。

2.
其它方法可以参见 WebBrowser Keystroke Problems等文章,不赘述
http://www.microsoft.com/mind/0499/faq/faq0499.asp



<< Home

This page is powered by Blogger. Isn't yours?