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.
It seems straight forward if, for example, I call the function from a mouse click because I can pass the event and check 'if (event.shiftKey)'. I don't have an event to check!
Many thanks
Chris
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With