1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.
  2. Better Analytics for WordPress Get It Free

Acces key script

Discussion in 'JavaScript' started by Zynex, Jan 15, 2007.

  1. #1
    Hi,

    I received a script for making my own acces keys. It works fine BUT it requires the visitor to press only 1 key. This is not handy.. esspecially on a page were you are filling out a form or using a search engine. I want a Key combination of 2 keys. For instance CTRL + y (it doesn't have to be ctrl but that's what I had in mind). Could someone look at the script, and maybe help me by making some ajustments?

    This is the script:

    <body onkeypress="if ((document.getElementById)&&(!document.all)){go_dest(event.which)}">

    <script type="text/javascript">
    keys="hyg"
    dest=["http://www.htmlforums.com","http://www.yahoo.com",
    "http://www.google.com"]
    if (document.layers)
    document.captureEvents(Event.KEYPRESS)
    function go_dest(e){
    for (i = 0; i < dest.length; i++){
    if (document.layers){
    if (e.which==keys.charCodeAt(i))
    window.location=dest
    }
    else if (document.all){
    if (event.keyCode==keys.charCodeAt(i))
    window.location=dest
    }
    else if ((document.getElementById)&&(!document.all)){
    if (e==keys.charCodeAt(i))
    window.location=dest
    }
    }
    }

    document.onkeypress=go_dest
    </script>

    </body>

     
    Zynex, Jan 15, 2007 IP
    NewTier likes this.
  2. smallbuzz

    smallbuzz Peon

    Messages:
    125
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think javascript can only detect 1 key press at a time.
     
    smallbuzz, Jan 16, 2007 IP
  3. giraph

    giraph Guest

    Messages:
    484
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You can do something like

    
    if (e.modifier().ctrl || e.modifier().meta) 
    {
          if (e.key().string == 'KEY_Y') 
         {
         }
    }
    
    Code (markup):
     
    giraph, Jan 17, 2007 IP