SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: onKeyclick

  1. #1
    SitePoint Zealot
    Join Date
    Dec 2002
    Location
    Asker, Norway
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onKeyclick

    Is it possible with javascript to press a key and an action will happen?
    Like <a onKeyClick(k)=windows.open("page2")
    So if you press the k button, you will come to page2

    Or if it's impossible, or very hard, can i press the right button somewhere in the page, and I will get to page2.
    like <body onRightClick=windows.open("page2")> ?

  2. #2
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Should be possible.
    I've seen javascript where a keypress allows you to move something around the screen.

    Check this out for some code that you can tweak.

    Additionally, here are some more links which may be more useful:
    Tech.irt.org
    Jscript.co.uk


    Andy
    From the English nation to a US location.

  3. #3
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    set onload to capturevents()
    hold down 'a' or 'd' and let go.

    Have a look here to find out key codes
    http://andrew-j.port5.com/test/keyCapture.html

    PHP Code:
    <script type="text/javascript">

     
    /*
        replace key numbers with appropriate keys

        have a look here to find keycapture codes

        [url]http://andrew-j.port5.com/test/keyCapture.html[/url]

      */


      
    var num 0;
      var 
    n   = (document.layers) ? true false;
      var 
    ie  = (document.all)    ? true false;

      function 
    capturevents() //driver
      
    {
        if (
    n//stub
        
    {
          
    alert('netscape');
        }
        else if (
    ie//stub
        
    {
          
    alert('internet explorer');
        }

        
    document.onkeydown keyDown;
        
    document.onkeyup keyUp;

        if (
    ndocument.captureEvents(Event.keydown Event.keyup);
      }

      function 
    keyDown(e)
      {
        if (
    n)
        {
          var 
    nKey  e.which;
          var 
    ieKey 0;
        }
        else if (
    ie)
        {
          var 
    ieKey event.keyCode;
          var 
    nKey  0;
        }

        if ((
    nKey == 97 || ieKey == 65))
        {
          
        }
        if ((
    nKey == 100 || ieKey == 68))
        {

        }
      }

      function 
    keyUp(e)
      {
        if (
    n)
        {
          var 
    nKey  e.which;
          var 
    ieKey 0;
        }

        if (
    ie)
        {
          var 
    ieKey event.keyCode;
          var 
    nKey  0;
        }
        if ((
    nKey == 97 || ieKey == 65 || nKey == 100 || ieKey == 68)) alert('keyup');
      }



    </script> 

  4. #4
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doh, got there too quick just as I was finishing writing that...

    ps, http://andrew-j.port5.com/test/keyCapture.html replaces the enter key with <br>


Bookmarks

Posting Permissions

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