Reputation: 657
In chrome, it seems that pressing alt will lock keydown/keyup callbacks. To reproduce, enter the following in a js console on any page:
var a = function(e){
console.log(e);
};
document.body.onkeydown = a;
document.body.onkeyup = a;
then click into the page and press keys, you should see key press and release events in the console. But if you press alt repeatedly, you'll notice you only see events for every second key press. In fact, if you press alt once, then press other keys, the events are swallowed. Am I going crazy? Wtf is this? To clarify, everything seems to work fine in firefox.
EDIT: works fine on chromium on linux, doesn't work on two windows machines, one 7, one 8
Upvotes: 0
Views: 254
Reputation: 87793
When you press Alt, the focus changes to the 3-bars menu icon in the top right corner, such that pressing Space would open said menu.
(Pressing Alt the second time will return focus to the web page.)
If this behavior is not desirable, you can try return false
or event.preventDefault()
in your keydown
event. This may or may not work depending on browser restrictions on the Alt key.
On my Windows 7, Firefox will open the File, Edit, View, etc menus when you press Alt. I am surprised if you are not seeing this behavior on yours.
Upvotes: 3