Closed Bug 583721 Opened 14 years ago Closed 14 years ago

onKey* events don't work correctly for non-ASCII characters

Categories

(Core :: DOM: Events, defect)

x86_64
Linux
defect
Not set
major

Tracking

()

RESOLVED DUPLICATE of bug 447757

People

(Reporter: gatekeeper.mail, Unassigned)

References

Details

(Whiteboard: [needs a testcase from the reporter])

User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; ru; rv:1.9.2.8) Gecko/20100723 Ubuntu/10.04 (lucid) Firefox/3.6.8
Build Identifier: Mozilla/5.0 (X11; U; Linux x86_64; ru; rv:1.9.2.8) Gecko/20100723 Ubuntu/10.04 (lucid) Firefox/3.6.8

Trying to get an event charcode for any cyrillic key pressed/Up with onKey* events always returns 0.

For example:
function keyEvt(e) {
  alert(e.which);
}

and an input like this: <input type="text" onKeyUp="keyEvt(event);" />
leads to alertbox with 0 when a cyrillic letter key is up after pressed.

Reproducible: Always
Please attach an actual testcase that can be used to reproduce the problem. You say "event charcode" first, then in the code example you use "e.which".
Component: General → DOM: Events
Product: Firefox → Core
QA Contact: general → events
Whiteboard: [needs a testcase from the reporter]
keyup listeners have only a keycode.  They don't have an associated character (so no charCode and no which).

If you want characters, use the keypress listener.
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → INVALID
Is it designed to return 0 to any non-latin character key being released (keyup) in linux (and almost no doubt any other UNIX-like X.org-based environment) and to return something else in Windows environment?

The actual testcase is like this:

<script type="text/javascript">
function keyevt(event) {
    alert(event.which);
}
</script>
<input type="text" onKeyUp="keyevt(event);" />

What and why is the difference between keypress and keyup listeners? I need to fire an event after something meaningful is entered into field so I need to first filter some cases out. And firing an event when KeyPress is confusing users in some cases (for example when triggering autocompletion - I either need to use KeyUp and bind some observer to such an event, like Horde project does and this is a _workaround_ to this bug or trigger KeyPress but display last entered char to a field by hacking it with some other JS code else it is displayed only after autocompleter gets shown which could take a while)
> Is it designed to return 0 to any non-latin character key being released
> (keyup) in linux (and almost no doubt any other UNIX-like X.org-based
> environment) and to return something else in Windows environment?

event.which will return the keyCode for keyup/down listeners and the charCode for keypress listeners (unless the key being pressed is the enter key or the backspace key).

It looks like on Linux in particular keyCodes have some issues.  See bug 447757.

> What and why is the difference between keypress and keyup listeners?

The former fires when a character is input, the latter when the key is released.  There may be multiple characters input between key press and key release (see key repeat).  All this information is pretty easily available via your favorite web search engine.

> I need to fire an event after something meaningful is entered into field

If you're interested in when things are entered, then keypress or input are the right events to watch for (the latter if you care about copy/paste and such).

Sounds like as filed this is a duplicate of bug
Resolution: INVALID → DUPLICATE
You need to log in before you can comment on or make changes to this bug.