Search

2/10/2014

#7300 (Keypress not getting arrow keys in chrome) – jQuery Core - Bug Tracker

Events - keydown, keypress, keyup

keypress Fires when an actual character is being inserted in, for instance, a text input. It repeats while the user keeps the key depressed.
JavaScript Madness: Keyboard Events
There are many other special keys on a typical keyboard that do not normally send characters. These include the four arrow keys, navigation keys like Home and Page Up, special function keys like Insert and Delete, and the function keys F1 through F12. Internet Explorer and WebKit 525 seem to classify all of these with the modifier keys, since they generate no text, so in those browsers there is no keypress event for them, only keyup and keydown. Many other browsers, like Gecko, do generate keypress events for these keys, however.
#7300 (Keypress not getting arrow keys in chrome) – jQuery Core - Bug Tracker
I've reviewed the bulk of tickets regarding keypress on both the Chrome, Chromium and Webkit bug trackers and it would appear that there are no intentions on supporting correct keypress behavior from any of these camps now or in the future. The reason for this is that a) keypress and its behavior is not mentioned specifically in any specs and b) Although FireFox and Opera support this feature, Webkit (used by Chrome and Safari) decided to copy the IE behavior in this case which reserves arrow keypresses for internal browser behavior only. There is no way that jQuery can circumvent this behavior and it is instead recommended that you use keydown instead as this is supported.
keyboard events -
Detecting arrow key presses in JavaScript - Stack Overflow Use keydown, not keypress for non-printable keys such as arrow keys:
function checkKey(e) {
    e = e || window.event;
    alert(e.keyCode);
}

document.onkeydown = checkKey;
arrow keys are only triggered by onkeydown, not onkeypress keycodes are: left = 37 up = 38 right = 39 down = 40

沒有留言: