I have been playing a lot with GreaseMonkey recently, and ran into a bug that was confusing.
I had added a key combo of Control-Return/Enter to do some work. Nothing was happening when I did that combo so I looked to see what was going wrong.
I put in:
window.addEventListener('keydown', function(e) { alert(e.keyCode); }, false);
and started keying around.
Hitting enter/return came up with 13. Good.
Control by itself returned 17. Good.
Control (left or right) and the main Return came back with 77 (which is M)
Control (left or right) and the Enter came back with 67 (which is C)
This is all on FF 2.0.1. Safari came back with flying colors (not much help for GreaseMonkey of course).
This means that if I hack it and capture all of the key combos, if someone really does do a Control-M or a Control-C it would ALSO fire off this event.
Has anyone else run into this? To me, it means that I have to choose another modifier key. Time for Shift-Return I guess.
January 12th, 2007 at 5:03 pm
I have a similar problem. I tried your code, as well as document.onkeydown = function(e){alert(e)}
I cant for the life of me get the modifier keys to trigger key events on their own. Using javascript keyboard events is looking like a minefield to me.
May 19th, 2008 at 1:41 am
forefox is not that good..
May 27th, 2009 at 6:41 pm
thanks for sharing,generous blogger