Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts

    capturing keystrokes for mozilla

    I've written this small script which handles onkeypress events for a webpage but i'd like to upgrade it so it is also compatible with Mozilla/Netscape 6. I was hoping that someone might be able to post up how to capture onkeypress events for mozilla.

    I actually validate the variable "key" (checking to see if it is a letter of the alphabet, etc) later on in catchKey()

    Code:
    var isNS4 = (document.layers);
    
    document.onkeypress = catchKey
    if (isNS4) document.captureEvents(Event.KEYDOWN)
    
    function catchKey(e) {
      var keyNum = (isNS4) ? e.which : event.keyCode;
      key = String.fromCharCode(keyNum).toLowerCase();
      
      alert(key);
    }
    Many thanks for your help.

    martin_narg
    Last edited by martin_narg; 04-04-2003 at 10:24 AM.
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeň, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Oh, for the third time or fourth time in a week's time, I'll post a link to the only page you'll need for anything that has to do with key events: <http://www.din.or.jp/~hagi3/JavaScri...s/KeyEvent.htm>

    Until the day all browsers support DOM Events...
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Many thanks!
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Originally posted by liorean
    Until the day all browsers support DOM Events...
    There is no current DOM Events way of handling the keyboard. DOM3 Events has TextEvent, but that's not in Candidate Recommendation yet, therefore browsers shouldn't implement it yet.

  • #5
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeň, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    It also has keydown and keyup. Anyway, in difference from css - where a change may force you to rewrite a lot of underlying code, which may have unintended effects on other rules and properties - DOM has a quite stable ground to built upon and implementating a feature is a good way to test if the feature and how it works is sound, or if it needs improvement. A change in DOM is less likely to affect other interfaces or features, and you usually can rewrite a method or property for a DOM interface without interfering with the rest of the DOM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

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