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 5 of 5
  1. #1
    Banned
    Join Date
    Jan 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Acces key script

    I just received a great script from someone for making your own acces keys. BUT I need the visitor to press a combination of 2 keys. For instance Ctrl + Y. Does anyone know how?

    here's the code

    <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[i]
    }
    else if (document.all){
    if (event.keyCode==keys.charCodeAt(i))
    window.location=dest[i]
    }
    else if ((document.getElementById)&&(!document.all)){
    if (e==keys.charCodeAt(i))
    window.location=dest[i]
    }
    }
    }

    document.onkeypress=go_dest
    </script>

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,778
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    
    <HTML>
    <HEAD>
    <TITLE></TITLE>
    </HEAD>
    
    <script type="text/javascript">
    
    function getKeys(e)
    {
        if (e.ctrlKey && e.keyCode == 89)
            alert('You have just pressed the Control and the Y key');
    }
    
    </script>
    
    <BODY>
    
    <textarea onKeyUp='getKeys(event);'></textarea>
    
    </BODY>
    </HTML>
    A list of keycodes are here: http://javascript.js-x.com/key_codes/
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    Banned
    Join Date
    Jan 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thats still not it... this script only works when youre cursor is on the textfield.

  • #4
    Regular Coder
    Join Date
    May 2006
    Posts
    181
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try this for cross-browser compatibility:
    Code:
    <script type="text/javascript">
    function getKeys(e){
    var key = (document.all)?event.keyCode:e.which;
    var ctrl = (document.all)?event.ctrlKey:e.ctrlKey;
        if(ctrl == true && key == 89){
            alert('You have just pressed the Control and the Y key');
        }
    }
    document.onkeyup = getKeys;
    </script>

  • #5
    Banned
    Join Date
    Jan 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thats it Finally. I tried for ages, and the solution is actualy 5 lines of code haha. Thank you very much!

    Zynex


  •  

    Posting Permissions

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