I have two event handlers: one for keydown and one for keyup. The keydown event handler fires a warning message, but this prevents the keyup event from being fired.
Here you can see a very simple example: http://jsfiddle.net/boblauer/jaGwT/ When keydown opens a warning, the keyboard does not start, but when the warning does not open, the key starts. Here is the code from jsfiddle:
var i = 0; window.addEventListener('keydown', function(e) { if (i++ % 2) alert('down'); console.log('down'); }); window.addEventListener('keyup', function(e) { alert('up'); console.log('up'); });
I have a library that supports listening to several key combinations (for example, "d + f"), so when a key is pressed, I need to add it to the list of pressed keys and when the key, I have to remove it from the specified list. The problem I am facing is that if I want a warning to be shown while pressing d + f at the same time, my code to remove these keys from the โcurrentlyโ list never fires because my keyup handler never gets called.
I canโt come up with a good job on this issue. Any ideas?
source share