function observeingKeys() {
console.log('watching keys now!');
$(document).observe('keypress', function(event){
switch (event.keyCode) {
case Event.KEY_UP:
console.log('Up');
break;
case Event.KEY_RIGHT:
console.log('Right');
break;
case Event.KEY_DOWN:
console.log('Down');
break;
case Event.KEY_LEFT:
console.log('Left');
break;
case 32: //Space
console.log('Space')
break;
case 13: //Return
console.log('Return')
break;
}
});
}
Here we are. First of all there is no “KEY_SPACE” or anything like that in the prototype framework, so the use of the actual keycode is unavoidable. In this case, the keycode for space is 32.
The code works for every case except for space.
Am I missing something or is it just not supported?
It appears that while FireFox4 uses keyCode for those other key events, for the Space Bar, it sets event.keyCode to 0, but event.charCode to 32.
EDIT: In fact, it appears that for most keys it uses charCode, but for some reason, on a few, such as Enter, it uses keyCode.