如何通过WRT widget处理按键
文章信息
代码示例
源文件: Media:Tetris.zip
测试基于
设备:: Nokia N78
兼容于
平台: S60 3rd Edition, FP2
文章
翻译:
由 hoolee
最后由 hamishwillee
在 20 Aug 2012 编辑
- 详细描述
如果你使用widget.setNavigationEnable(false);屏蔽光标移动,那么在web runtime(WRT)中,你将需要完成自己的按键处理方法。
当将JavaScript脚本程序导入到WRT时,原有的交互操作不一定能在S60手机输入方法下顺利工作,你需要修改以便适应平台。下面这个示例将演示导航键的处理。
- 解决方案
首先启动键盘捕捉,当程序启动时调用下列代码:
document.addEventListener("keypress", this.keypressListener, false);
然后当你离开程序后记得移除这个事件捕捉,操作如下:
document.removeEventListener("keypress", this.keypressListener, false);
你需要按照如下方法完成按键事件监听方法,并处理按键事件:
this.keypressListener = function(event) {
if(event.keyCode == 63495) // left
{
// call the function that handles the left arrow key
}
else if(event.keyCode == 63496) // right
{
// call the function that handles the right arrow key
}
else if(event.keyCode == 63497) // up
{
// call the function that handles the up arrow key
}
else if(event.keyCode == 63498) // down
{
// call the function that handles the down arrow key
}
else if(event.keyCode == 63557) // middle button
{
// call the function that handles the middle button
}
};
- 相关资源
可以使用这个程序File:Tetris.zip导入S60 WRT环境。原代码是为PC浏览器环境服务的,可参考Browser Tetris


(no comments yet)