How to hook IE keyboard event?

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.

Answers:

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

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.