www.webdeveloper.com
Results 1 to 13 of 13

Thread: Opera misfires keydown and keypress

  1. #1
    Join Date
    May 2008
    Posts
    80

    Angry Opera misfires keydown and keypress

    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?


    Thank you.

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    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.

  3. #3
    Join Date
    May 2008
    Posts
    80
    Quote Originally Posted by Kor View Post
    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.

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by the_dp View Post

    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

  5. #5
    Join Date
    May 2008
    Posts
    80
    But does onkeyup provides me with the same key value as onkeydown?

    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.

  6. #6
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by the_dp View Post
    But does onkeyup provides me with the same key value as onkeydown?
    Yes.
    Quote Originally Posted by the_dp View Post
    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?

  7. #7
    Join Date
    May 2008
    Posts
    80
    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

    Thank you for your help.

  8. #8
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by the_dp View Post
    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.

  9. #9
    Join Date
    May 2008
    Posts
    80
    Quote Originally Posted by Kor View Post
    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.
    It not a textarea. It's the page itself.
    Last edited by the_dp; 09-01-2009 at 06:44 AM.

  10. #10
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by the_dp View Post
    It not a textarea. It's the page itself.
    But the user must type something somewhere. Where?

  11. #11
    Join Date
    May 2008
    Posts
    80
    Anywhere inside the frame.
    The entire frame is the editor itself.

  12. #12
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    A Modal Window?

  13. #13
    Join Date
    May 2008
    Posts
    80
    Quote Originally Posted by Kor View Post
    A Modal Window?
    I guess you can call it that way

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles