Question

i try to capture this key : alt+arrow down, alt+arrow up. First, i capture alt key down :

var isAlt = false;
$(document).keydown(function (e) {  
    if(e.which == 18){isAlt=true;} 
}).keyup(function (e) {
    if(e.which == 18){isAlt=false;}
});

this code is ok, and alt keyup is detected.

But, if i add arrow key down, when arrow keydown, it's ok, but after alt keyup is not detected :

var isAlt = false;
$(document).keydown(function (e) {  
    if(e.which == 18){isAlt=true;}else{
        if(e.which == 38 && isAlt == true) {
             //action code here work
             console.log('action ok');
        }
    }
}).keyup(function (e) {
    if(e.which == 18){isAlt=false;}
});

You can try this on console, and after log 'action ok', you need press again alt key for "isAlt = false". But, this code work fine on Chrome.

Anyone have one idea for correct this bug ?

Was it helpful?

Solution

You need to check the event.altKey property: https://developer.mozilla.org/en/DOM/KeyboardEvent

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top