Closed
Bug 263145
Opened 20 years ago
Closed 20 years ago
KeyCode of "Escape" is different in onKeyPress and onKeyUp
Categories
(Core :: DOM: Events, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: traumwandler, Unassigned)
Details
Attachments
(1 file)
|
308 bytes,
text/html
|
Details |
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040803 Firefox/0.9.3
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040803 Firefox/0.9.3
If you add a listener to the onKeyPress event, you get KeyCode == 0 if you press
the escape Key. If you add the same listener to onKeyUp you get KeyCode == 27 by
pressing the escape Key.
Reproducible: Always
Steps to Reproduce:
1. Create a HTML Page
2. Add
<script>
window.onkeypress = function(e) {
document.body.innerHTML = "onKeyPress: "+e.which;
}
window.onkeyup = function(e) {
document.body.innerHTML = document.body.innerHTML + " / onKeyUp" + e.which;
}
</script>
to the content.
3. Open the .html file and press escape.
Actual Results:
Output display:
onKeyPress: 0 / onKeyUp: 27
Expected Results:
Output display:
onKeyPress: 27 / onKeyUp: 27
Comment 1•20 years ago
|
||
Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.8a5) Gecko/20041002 I made a testcase, which I will upload. Results below, 'Press ESC: ' is text from the testcase, testcase gives: onKeyPress: 0 / onKeyUp27 ESC The keys, as seen by another testcase: https://bugzilla.mozilla.org/attachment.cgi?id=55849&action=view 1) keydown charCode=0 keyCode=27 2) keypress charCode=0 keyCode=27 3) keyup charCode=0 keyCode=27 If I watch the behaviour of the TAB key, the onKeyPress event gets consumed, if focus walks away to Location Bar, and gets noted, if focus returns to the window. I´ll confirm, that somebody better in the know can resolve the bug. I´ve tested some other keys with the attached testcase: onKeyPress: 0 TAB, then focus elsewhere onKeyPress: 0 / onKeyUp9 TAB, then focus in Window Press ESC: / onKeyUp20 Shift-Lock, only once Press ESC: / onKeyUp20 / onKeyUp16 Left Shift (Shift-Lock was on) Press ESC: / onKeyUp16 Left Shift, RightShift Press ESC: / onKeyUp17 LeftCtrl, RightCtrl Press ESC: / onKeyUp18 Alt Press ESC: / onKeyUp17 / onKeyUp18 AltGr onKeyPress: 0 / onKeyUp37 CursorLeft,NumCsrLft
Status: UNCONFIRMED → NEW
Ever confirmed: true
Comment 2•20 years ago
|
||
testcase can be used with any key
Comment 3•20 years ago
|
||
With letter keys, for some reason onKeyPress is returning the KeyCode of the capital letter while onKeyUp is returning the actual KeyCode. You can see this by either turning Caps Lock on then pressing and releasing letter keys, or holding shift as you press and release them. This bug seems to apply to almost any key you press, including the F-keys.
Comment 4•20 years ago
|
||
That testcase is looking at .which, not .keyCode. The latter is the keycode. The former is there for backwards compat with NS4; in NS4 keypress events .which is the charCode unless it's a return/backspace keypress, in which case it's the keycode. Marking invalid.
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•