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 2 of 2

Thread: OnKeyDown event

  1. #1
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    OnKeyDown event

    I would like to know how to use the onkeydown event to record when I use the arrow keys.

    Also, I would like that when my arrow keys are pressed, it goes to a link.


    For example, if I pressed my up arrow key it would go to http://www.google.com, if I pressed my down arrow key it would go to http://www.yahoo.com, etc.

    the key numbers are:

    Left Arrow = 37
    Up Arrow = 38
    Right Arrow = 39
    Down Arrow = 40

    Thanks for any help.
    Last edited by Shindig; 12-24-2004 at 05:31 PM.

  • #2
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You'll want to do something like this -

    Code:
    <script language="javascript" type="text/javascript"> 
    <!-- 
              document.onkeydown = function keyPress(evt) 
                   { 
                   var keyCode = 
                   document.layers ? evt.which : 
                   document.all ? event.keyCode : 
                   document.getElementById ? evt.keyCode : 0; 
                   if (keyCode == 38) 
                        {__doPostBack(document.location="http://www.google.com",'')} 
                   else if (keyCode == 40) 
                        {__doPostBack(document.location="http://www.yahoo.com",'')} 
                   } 
              //--> 
              </script>
    Last edited by mark87; 12-24-2004 at 06:13 PM.


  •  

    Posting Permissions

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