Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-25-2009, 07:48 AM   PM User | #1
dhruvg
New to the CF scene

 
Join Date: Mar 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
dhruvg is an unknown quantity at this point
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!
dhruvg is offline   Reply With Quote
Old 03-25-2009, 03:54 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,687
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
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.
__________________
Fumigator is offline   Reply With Quote
Old 03-25-2009, 04:03 PM   PM User | #3
TinyScript
Regular Coder

 
Join Date: Mar 2009
Location: Portland Oregon
Posts: 690
Thanks: 44
Thanked 63 Times in 62 Posts
TinyScript is on a distinguished road
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>
TinyScript is offline   Reply With Quote
Old 03-25-2009, 04:11 PM   PM User | #4
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,687
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
...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
__________________
Fumigator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:05 AM.


Advertisement
Log in to turn off these ads.