?
Solved

document.captureEvents(Event.KEYDOWN); and Netscape 6+

Posted on 2003-03-14
10
Medium Priority
?
263 Views
Last Modified: 2008-02-01
This statement seems to enable keypress listening for NN4, but seems not to work for version 6 and above.

What's the alternative??
0
Comment
Question by:boatful
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 4

Expert Comment

by:whammy
ID: 8140690
What statement?

quote:

=====================
This statement seems to enable keypress listening for NN4, but seems not to work for version 6 and above.

What's the alternative??
=====================
0
 
LVL 4

Expert Comment

by:whammy
ID: 8140693
Have you tried onkeypress?
0
 
LVL 4

Expert Comment

by:whammy
ID: 8140697
P.S. You might benefit from this:

http://www.solidscripts.com/displayscript.asp?sid=12

:)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:sh0e
ID: 8144992
are you sure you have the code written correctly?
just in case heres a snippet from http://javascriptkit.com/javatutors/javascriptkey3.shtml
that shows the proper way to capture keypress
<script language="JavaScript1.2">

//Step1: Capture the keyboard event
document.captureEvents(Event.KEYPRESS)
//Step 2: Create the reacting function
function processkey(e){
alert("You pressed a key!")
}
//Step 3: Hook the two up
document.onkeypress=processkey

</script>

in any case it would help to know in what context you are using the keypress event
as it should be working under netscape 6+
0
 

Expert Comment

by:kn_sridhar
ID: 8151240
Hi

Just try this code.

function keyDown()
{
    if(document.all)
    {
        keyChar = String.fromCharCode(event.keyCode);
        if(event.keyCode == <<your key>>)
        {
           <<DO SOMETHING>>
        }
    }
    else
    {
        keyChar = String.fromCharCode(e.which);
        if(e.which == <<your key>>)
        {
           <<DO SOMETHING>>
        }    
    }
}

Regards
0
 

Expert Comment

by:kn_sridhar
ID: 8151247
Hi

Just try this code.

function keyDown()
{
    if(document.all)
    {
        keyChar = String.fromCharCode(event.keyCode);
        if(event.keyCode == <<your key>>)
        {
           <<DO SOMETHING>>
        }
        document.onkeypress = keyDown;
    }
    else
    {
        keyChar = String.fromCharCode(e.which);
        if(e.which == <<your key>>)
        {
           <<DO SOMETHING>>
        }    
        document.onkeypress = keyDown;
        document.captureEvents(Event.KEYPRESS);
    }
}

Regards
0
 

Author Comment

by:boatful
ID: 8201701
whammy's http://www.solidscripts.com/displayscript.asp?sid=12 is cool, but tangential to my question.

sh0e's http://javascriptkit.com/javatutors/javascriptkey3.shtml was last updated in 1998, so does not really address the NN6 part of my question

I realize that I gave little/no context for my question, but the code I am writing for this web-enabled application depends heavily on DHTML to make the main document function as though it were several framed documents, and thus the code is not easy to follow (1000 lines or more).

I want to give away these points, but I need to try to get the code provided by kn_sridhar (above) to work for NN6 before I do so.
0
 
LVL 4

Accepted Solution

by:
whammy earned 375 total points
ID: 8206967
Actually the link I provided isn't entirely tangential...

I thought that the way I caught the events might be of particular use to you cross-browser (especially since it works in Netscape 6/Mozilla/Netscape 4/ IE 4+), i.e.:

   var k;
   document.all ? k = e.keyCode : k = e.which;

using something like that, k will be assigned the keycode for the event which is passed as an arg to the function parameter. Quickest cross-browser parsing script I have written yet in .js anyway. ;-)
0
 
LVL 4

Expert Comment

by:whammy
ID: 8206974
P.S. Using onkeydown doesn't work with everything (I don't remember what, exactly, offhand!) - for those situations in which it does not work I would try onkeypress. ;-)
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10131157
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: whammy {http:#8206967}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question