Skip to content Skip to sidebar Skip to footer

Javascript Detect 'shift' Key Down Within Another Function

I am calling a Javascript function in my html page from a Flash movie (using ExternalInterface) and I want to know if the user has the Shift key down when the function is called. I

Solution 1:

Attach a keydown and keyup event to the document on the page and listen for the shift key.

var shiftDown = false;
var setShiftDown = function(event){
    if(event.keyCode === 16 || event.charCode === 16){
        window.shiftDown = true;
    }
};

var setShiftUp = function(event){
    if(event.keyCode === 16 || event.charCode === 16){
        window.shiftDown = false;
    }
};

window.addEventListener? document.addEventListener('keydown', setShiftDown) : document.attachEvent('keydown', setShiftDown);
window.addEventListener? document.addEventListener('keyup', setShiftUp) : document.attachEvent('keyup', setShiftUp);

Post a Comment for "Javascript Detect 'shift' Key Down Within Another Function"