Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

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

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

What's the alternative??
0
boatful
Asked:
boatful
1 Solution
 
whammyCommented:
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
 
whammyCommented:
Have you tried onkeypress?
0
 
whammyCommented:
P.S. You might benefit from this:

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

:)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
sh0eCommented:
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
 
kn_sridharCommented:
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
 
kn_sridharCommented:
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
 
boatfulAuthor Commented:
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
 
whammyCommented:
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
 
whammyCommented:
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
 
jaysolomonCommented:
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

Technology Partners: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now