gpt4 book ai didi

javascript - 如何 Hook IE键盘事件?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:37:47 26 4
gpt4 key购买 nike

我试图在用户尝试按 swf 文件上的某些组合键时禁用浏览器快捷方式。虽然我可以在 Firefox 中实现这一点,但下面的代码在 IE 8 中不起作用。如果焦点不在 swf 文件上,下面的代码能够挂接键盘事件。但是,我需要的是在用户操作 swf 文件时挂接键盘事件。

function hookKeyboardEvents(e) {

alert("hooked key");
// get key code
var key_code = (window.event) ? event.keyCode : e.which;

// case :if it is IE event
if (window.event)
{
if (!event.shiftKey && !event.ctrlKey && !event.altKey) {
window.event.returnValue = null;
event.keyCode=0;
}
}
// case: if it is firefox event
else
e.preventDefault();

document[flashId].keyDown(key_code);
}

window.document.onkeydown = hookKeyboardEvents;

当焦点在 swf 文件上时,以上代码永远不会执行。

最佳答案

document.body.accessKey = String.fromCharCode(e.keyCode);

关于javascript - 如何 Hook IE键盘事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1426585/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com