How to hook IE keyboard event?

假装没事ソ 提交于 2019-12-07 08:02:20

问题


I am trying to disable browser shortcuts while user tries to press some combination of keys on the swf file. Although I can achieve this in Firefox, below code does not function in IE 8. Below code is able to hook the keyboard events if focus is not on the swf file. However, what I need is hooking keyboard events when user operates on swf file.

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;

Above code never executes when focus is on swf file.


回答1:


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


来源:https://stackoverflow.com/questions/1426585/how-to-hook-ie-keyboard-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!