Monday, 15 February 2010

javascript - JS Detecting key press without an event object -



javascript - JS Detecting key press without an event object -

i have javascript application, enters special state when keypress event contains command key (either ctrl, cmd, shift). when keyup event fires, app leaves state.

the current code looks this:

$(window).keydown -> if [16, 17, 91, 93, 224].indexof(e.which) >= 0 # cmd, ctrl, shift # come in special mode $(window).keyup -> if [16, 17, 91, 93, 224].indexof(e.which) >= 0 # cmd, ctrl, shift # exit special mode

the problem if press ctrl/cmd+t, example, open new tab, app enters state, never receives keyup event, doesn't leave it, unless press cmd key again.

the ideal prevent select mode beingness activated when cmd+t pressed, launching loop checks whether key still pressed ok workaround. question is, how can check if key still pressed, without event present?

have tried going out of special mode when window blurs? can timeouts window left behind , start piling up. this:

$(window).blur(function(){ // escape special mode });

this allows unset keeps going while window not focused. can homecoming of released triggers using $(window).focus event.

javascript jquery

No comments:

Post a Comment