[jQuery] Re: Detecting Ctrl + click

2008-09-12 Thread [EMAIL PROTECTED]

Hi there,

Does the "if(e.ctrlKey) {"  apply also for Macs?  I know a Mac doesn't
have a Ctrl key as such, but it has some key that allows for multiple
selections of things.

 - Dave


On Sep 11, 2:10 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Just do something like this:
>
> $(document).click(function(e) {
>   if(e.ctrlKey) {
>     console.log("Ctrl+Click");
>     // your code goes here...
>   } else if(e.altKey) {
>     console.log("Alt+Click");
>   } else if(e.shiftKey) {
>     console.log("Shift+Click");
>   }
>
> });
>
> I have just add 2 other events
>
> On 11 Sep., 21:28, "[EMAIL PROTECTED]"
>
>
>
> <[EMAIL PROTECTED]> wrote:
> > Thanks both for your input.  I guess the question is, there cleraly
> > seems to be a way to detect if a key is pressed, and there is a way to
> > define a click event, but how would I do a combination?
>
> > Is the easiest way to capture the event when the Ctrl key is pressed,
> > set a flag, and check if that flag is still set when I catch the mouse
> > click event?
>
> >  - Dave
>
> > On Sep 11, 7:37 am, owen <[EMAIL PROTECTED]> wrote:
>
> > > I've had some success with the hotkeys plugin:
>
> > >http://code.google.com/p/js-hotkeys/
>
> > > Check out the demo:http://jshotkeys.googlepages.com/test-static-01.html
>
> > >   -- Owen- Hide quoted text -
>
> - Show quoted text -


[jQuery] Re: Detecting Ctrl + click

2008-09-12 Thread BB

Just something I would like to add:
if you now say: e.altKey doesn't work!!
it is right... but will be fixed in the next release of jQuery, see:
http://dev.jquery.com/ticket/2947

On 11 Sep., 22:10, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Just do something like this:
>
> $(document).click(function(e) {
>   if(e.ctrlKey) {
>     console.log("Ctrl+Click");
>     // your code goes here...
>   } else if(e.altKey) {
>     console.log("Alt+Click");
>   } else if(e.shiftKey) {
>     console.log("Shift+Click");
>   }
>
> });
>
> I have just add 2 other events
>
> On 11 Sep., 21:28, "[EMAIL PROTECTED]"
>
> <[EMAIL PROTECTED]> wrote:
> > Thanks both for your input.  I guess the question is, there cleraly
> > seems to be a way to detect if a key is pressed, and there is a way to
> > define a click event, but how would I do a combination?
>
> > Is the easiest way to capture the event when the Ctrl key is pressed,
> > set a flag, and check if that flag is still set when I catch the mouse
> > click event?
>
> >  - Dave
>
> > On Sep 11, 7:37 am, owen <[EMAIL PROTECTED]> wrote:
>
> > > I've had some success with the hotkeys plugin:
>
> > >http://code.google.com/p/js-hotkeys/
>
> > > Check out the demo:http://jshotkeys.googlepages.com/test-static-01.html
>
> > >   -- Owen


[jQuery] Re: Detecting Ctrl + click

2008-09-11 Thread [EMAIL PROTECTED]

Just something I would like to add:
if you now say: e.shiftKey doesn't work!!
it is right... but will be fixed in the next release of jQuery, see:
http://dev.jquery.com/ticket/2947

On 11 Sep., 22:10, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Just do something like this:
>
> $(document).click(function(e) {
>   if(e.ctrlKey) {
>     console.log("Ctrl+Click");
>     // your code goes here...
>   } else if(e.altKey) {
>     console.log("Alt+Click");
>   } else if(e.shiftKey) {
>     console.log("Shift+Click");
>   }
>
> });
>
> I have just add 2 other events
>
> On 11 Sep., 21:28, "[EMAIL PROTECTED]"
>
> <[EMAIL PROTECTED]> wrote:
> > Thanks both for your input.  I guess the question is, there cleraly
> > seems to be a way to detect if a key is pressed, and there is a way to
> > define a click event, but how would I do a combination?
>
> > Is the easiest way to capture the event when the Ctrl key is pressed,
> > set a flag, and check if that flag is still set when I catch the mouse
> > click event?
>
> >  - Dave
>
> > On Sep 11, 7:37 am, owen <[EMAIL PROTECTED]> wrote:
>
> > > I've had some success with the hotkeys plugin:
>
> > >http://code.google.com/p/js-hotkeys/
>
> > > Check out the demo:http://jshotkeys.googlepages.com/test-static-01.html
>
> > >   -- Owen
>
>


[jQuery] Re: Detecting Ctrl + click

2008-09-11 Thread [EMAIL PROTECTED]

Just do something like this:

$(document).click(function(e) {
  if(e.ctrlKey) {
console.log("Ctrl+Click");
// your code goes here...
  } else if(e.altKey) {
console.log("Alt+Click");
  } else if(e.shiftKey) {
console.log("Shift+Click");
  }
});

I have just add 2 other events

On 11 Sep., 21:28, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Thanks both for your input.  I guess the question is, there cleraly
> seems to be a way to detect if a key is pressed, and there is a way to
> define a click event, but how would I do a combination?
>
> Is the easiest way to capture the event when the Ctrl key is pressed,
> set a flag, and check if that flag is still set when I catch the mouse
> click event?
>
>  - Dave
>
> On Sep 11, 7:37 am, owen <[EMAIL PROTECTED]> wrote:
>
> > I've had some success with the hotkeys plugin:
>
> >http://code.google.com/p/js-hotkeys/
>
> > Check out the demo:http://jshotkeys.googlepages.com/test-static-01.html
>
> >   -- Owen
>
>


[jQuery] Re: Detecting Ctrl + click

2008-09-11 Thread [EMAIL PROTECTED]

Thanks both for your input.  I guess the question is, there cleraly
seems to be a way to detect if a key is pressed, and there is a way to
define a click event, but how would I do a combination?

Is the easiest way to capture the event when the Ctrl key is pressed,
set a flag, and check if that flag is still set when I catch the mouse
click event?

 - Dave


On Sep 11, 7:37 am, owen <[EMAIL PROTECTED]> wrote:
> I've had some success with the hotkeys plugin:
>
> http://code.google.com/p/js-hotkeys/
>
> Check out the demo:http://jshotkeys.googlepages.com/test-static-01.html
>
>   -- Owen


[jQuery] Re: Detecting Ctrl + click

2008-09-11 Thread owen

I've had some success with the hotkeys plugin:

http://code.google.com/p/js-hotkeys/

Check out the demo: http://jshotkeys.googlepages.com/test-static-01.html

  -- Owen


[jQuery] Re: Detecting Ctrl + click

2008-09-11 Thread Andy Matthews

Should just be a matter of checking the keypress event:

http://docs.jquery.com/Events/keypress#fn

 

-Original Message-
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of [EMAIL PROTECTED]
Sent: Wednesday, September 10, 2008 6:10 PM
To: jQuery (English)
Subject: [jQuery] Detecting Ctrl + click


Hi,

How could I detect someone holding down the Ctrl key and then clicking the
mouse button on something?  Similar question for the Mac -- holding down the
Shift key and clicking the mouse button.

 - Dave




[jQuery] Re: Detecting ctrl+click on an element

2008-02-04 Thread Giovanni Battista Lenoci


Jeffrey Kretz ha scritto:

Another way would be to use the ctrlKey property of the Click event:

$('#element').click(function(e)
{
if (e.ctrlKey)
{
do_something();
}
});

jQuery also normalizes this into the metaKey attribute which detects the CMD
key on a Mac:

$('#element').click(function(e)
{
if (e.metaKey)
{
do_something();
}
});
  

Very cool, thank you all.

--
gianiaz.net - Giovanni Battista Lenoci 
P.le Bertacchi 66 
23100 Sondrio (SO) - Italy




[jQuery] Re: Detecting ctrl+click on an element

2008-02-04 Thread andrea varnier

On 4 Feb, 17:20, "Jeffrey Kretz" <[EMAIL PROTECTED]> wrote:
> Another way would be to use the ctrlKey property of the Click event:
>
> $('#element').click(function(e)
> {
> if (e.ctrlKey)
> {
> do_something();
> }
> });
>
> jQuery also normalizes this into the metaKey attribute which detects the CMD
> key on a Mac:
>
> $('#element').click(function(e)
> {
> if (e.metaKey)
> {
> do_something();
> }
> });

LOL!! much simpler.
thanks, I didn't know that :)


[jQuery] Re: Detecting ctrl+click on an element

2008-02-04 Thread Jeffrey Kretz

Another way would be to use the ctrlKey property of the Click event:

$('#element').click(function(e)
{
if (e.ctrlKey)
{
do_something();
}
});

jQuery also normalizes this into the metaKey attribute which detects the CMD
key on a Mac:

$('#element').click(function(e)
{
if (e.metaKey)
{
do_something();
}
});
-Original Message-
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of andrea varnier
Sent: Monday, February 04, 2008 6:35 AM
To: jQuery (English)
Subject: [jQuery] Re: Detecting ctrl+click on an element


On 4 Feb, 14:38, Giovanni Battista Lenoci <[EMAIL PROTECTED]> wrote:
> The subject says it all...
>
> How I can detect a crtl+click on an element?

try this, supposing #target is yout target

var clickFn = function(){
alert("ctrl + click");
$(this).unbind('click', clickFn);
}

$(document)
.keydown(function(event){
if (event.keyCode == 17){
$("#target").click(clickFn);
}
})
.keyup(function(event){
if (event.keyCode == 17){
$("#target").unbind('click', clickFn);
}
});



[jQuery] Re: Detecting ctrl+click on an element

2008-02-04 Thread andrea varnier

On 4 Feb, 16:15, Giovanni Battista Lenoci <[EMAIL PROTECTED]> wrote:
> I was making some test, and I have little problem..
>
> If I bind a function to an element with jquery style method:
>
> $('#target').bind('click', function() { dosomething(this); ) });
>
> in my dosomething function I can retrieve the element clicked.
>
> With your syntax I can bind/unbind function but I can't call dosomething
> with this parameter.

look at my code:

var clickFn = function(){
alert("ctrl + click");
$(this).unbind('click', clickFn);
}

you can still get what you need by using $(this) in the function
for example:

var $this = $(this);
dosomething($this);

naming the function is useful if your #target element has other
functions bound to a click event.
in that case doing a simple
$("#target").unbind('click');
would unbind even functions you may want to keep.

> Thank you..

figurati, you're welcome :)


[jQuery] Re: Detecting ctrl+click on an element

2008-02-04 Thread Giovanni Battista Lenoci


andrea varnier ha scritto:

try this, supposing #target is yout target

var clickFn = function(){
alert("ctrl + click");
$(this).unbind('click', clickFn);
}

$(document)
.keydown(function(event){
if (event.keyCode == 17){
$("#target").click(clickFn);
}
})
.keyup(function(event){
if (event.keyCode == 17){
$("#target").unbind('click', clickFn);
}
});

  

I was making some test, and I have little problem..

If I bind a function to an element with jquery style method:

$('#target').bind('click', function() { dosomething(this); ) });

in my dosomething function I can retrieve the element clicked.

With your syntax I can bind/unbind function but I can't call dosomething 
with this parameter.


Sorry, I'm using jquery for awhile, but in javascript I'm very newbie...

Thank you..


--
gianiaz.net - Giovanni Battista Lenoci 
P.le Bertacchi 66 
23100 Sondrio (SO) - Italy




[jQuery] Re: Detecting ctrl+click on an element

2008-02-04 Thread Giovanni Battista Lenoci


andrea varnier ha scritto:

try this, supposing #target is yout target

var clickFn = function(){
alert("ctrl + click");
$(this).unbind('click', clickFn);
}

$(document)
.keydown(function(event){
if (event.keyCode == 17){
$("#target").click(clickFn);
}
})
.keyup(function(event){
if (event.keyCode == 17){
$("#target").unbind('click', clickFn);
}
});

  

Thank you very much!



--
gianiaz.net - Giovanni Battista Lenoci 
P.le Bertacchi 66 
23100 Sondrio (SO) - Italy




[jQuery] Re: Detecting ctrl+click on an element

2008-02-04 Thread andrea varnier

On 4 Feb, 14:38, Giovanni Battista Lenoci <[EMAIL PROTECTED]> wrote:
> The subject says it all...
>
> How I can detect a crtl+click on an element?

try this, supposing #target is yout target

var clickFn = function(){
alert("ctrl + click");
$(this).unbind('click', clickFn);
}

$(document)
.keydown(function(event){
if (event.keyCode == 17){
$("#target").click(clickFn);
}
})
.keyup(function(event){
if (event.keyCode == 17){
$("#target").unbind('click', clickFn);
}
});