I have a JavaScript application that receives keydown and keypress events from the user. The application works great in IE, Firefox, Safari and Chrome, yet it acts weird under Opera.
While in other browsers, if the user holds down a key, both events continue to fire... But in Opera the events fire only once while the key is still pressed.
Is there a reason to Opera's behaviour? How can I adapt myself to solve this issue?
What that application does? Maybe we can find another approach. If it's about a form's control validation, there are solutions with onkeyup and onblur.
What that application does? Maybe we can find another approach. If it's about a form's control validation, there are solutions with onkeyup and onblur.
This part of the system is extremely complex because there is no real standard to keyboard input, every browser on every OS does whatever they want... You just can't be sure what was actually pressed by the user, example: The keydown of arrows gives you letters... WTF.
After working on the feature for over a month, I finally managed to map the entire keyboard keys correctly, by cross examining values received from both keydown and keypress events.
So I don't think it's a good idea to look for a difference approch at this point... Not for a browser with less than 2% coverage.
In other words, if I won't be able to find a bypass to this misfiring issue, we will simply drop Opera support.
Also, I doubt if onkeyup will act differently than onkeydown and onkeypress.
Also, I doubt if onkeyup will act differently than onkeydown and onkeypress.
Don't. onkeyup is the only key event which works in the same manner in all the browsers.
onkeydown:
- in Opera you can not prevent the default onkeydown
- the event onkeydown does not repeat neither in Opera nor in Konqueror
onkeypress:
- some browsers fire the event too many times (Opera, Firefox, Safari) - this event should leads only to a character being added to an HTML element (such as an text input)
- not available on iPhone 3G
But does onkeyup provides me with the same key value as onkeydown?
Yes.
Originally Posted by the_dp
The feature I'm working on is a rich text editor, that I'm writing text to it by receiving input from the keyboard and displaying it in the html page.
Hmm... I usually avoid capturing the keystrokes, as the key events are so unpredictable in different browsers. On the other hand, a keystroke does not necessarily returns the same letter. User might use a different keyboard or a certain font type which might return unpredictable special characters. Moreover, the user might not use his keyboard to input a text, but the mouse's Copy/Paste facility.
Tell us: where do you use onkeypress and onkeydown? To do what?
As I said, I'm working on a rich text editor, using the captured events from the keyboard (after horrific mapping ) and displaying them on the screen as html.
I did a long research into the issue back when the development began. It was the only way to gain full control.
As for the unpredictability... You're right, I had to work really hard to make it compatible to main stream browsers (IE, Firefox & Safari/Chrome) and OSs (Linux, Windows & Mac OS). This is exactly why I would actually consider to drop Opera support before touching the mapping mechanism.
I will try to embed the onkeyup event... Who knows, maybe it will be a smooth plug and play
As I said, I'm working on a rich text editor, using the captured events from the keyboard (after horrific mapping ) and displaying them on the screen as html.
can't you simply transfer the value of the text editor (editor which is nothing but a TEXTAREA, right?) ? That value returns exactly the string written within that TEXTAREA.
can't you simply transfer the value of the text editor (editor which is nothing but a TEXTAREA, right?) ? That value returns exactly the string written within that TEXTAREA.
Bookmarks