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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    function - element is clicked while SHIFT key is pressed

    hi.

    i am trying to build a function that takes into account a click event AND SHIFT key press event on a particular element.

    so for example, i want to do something only when i click a box WHILE pressing the SHIFT key.

    how do i program this using jquery?

    thanks much!

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Interesting... typically shift+click isn't an event that is captured by Javascript, because it's not low-level enough (such as C). But.. there is the keydown event, so in theory you can detect when the shift key is pressed down (see the coding example on this page) and when a key is released (keyup), so I don't see why you couldn't turn a boolean variable on when shift is pressed down and back off when shift is released, and then you can check inside your click event function to see if that variable is on or off (which would indicate if shift is pressed or not). I'll have to try that out; it could come in handy.

  • #3
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    Here's an event capture, but shift is not one of the events triggered. I'd like to know how to do it too. I'm going to hit the google.

    Code:
    <html>
    <head>
    </head>
    <body>
    
    
    <script type="text/javascript">
    function handler(e) {
     var eve        = (e?e:event);
     var code       = (eve.charCode?eve.charCode:eve.keyCode);
     document.body.appendChild(document.createTextNode("You press :"+code));
     document.body.appendChild(document.createElement("br"));
     alert(eve);
    }
    document.onkeypress=handler;
    document.body.appendChild(document.createTextNode(f.xd.onkeypress));
    </script>
    </body>
    </html>

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    ...And as I was hoping, a plugin has been written for this very thing, called extendedclick. It will detect shift+click, alt+click, ctrl+click and combinations of shift, alt, and ctrl. HANDY!

    http://plugins.jquery.com/project/extendedclick

    Demonstration:

    http://minuscreative.com/jquery


  •  

    Posting Permissions

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