Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #23191

Re: How to detect key pressed plus mouse click, e.g., ctrl + left click

Message-ID <3506285.IpskKQNfjB@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2014-02-22 10:54 +0100
Subject Re: How to detect key pressed plus mouse click, e.g., ctrl + left click
Newsgroups comp.lang.javascript
References <pe7fg9dfqg4omh5u888q0vnduas63i47d3@4ax.com> <XnsA2DBCC37E59CCeejj99@194.109.133.133> <tn9fg95v13j6c51bjs89qidr75s5kttk3g@4ax.com> <XnsA2DBD0E11E61Eeejj99@194.109.133.133> <LaidnWADIL12nJXOnZ2dnUVZ_i2dnZ2d@westnet.com.au>

Show all headers | View raw


Andrew Poulos wrote:

> On 22/02/2014 6:32 AM, Evertjan. wrote:
>> document.onmousedown = function(e) {
>>    var e = e || window.event;
>>    if (e.shiftKey || e.altKey || e.ctrlKey)
>>      alert ( "shiftKey=" + e.shiftKey + "\naltKey="
>>      + e.altKey + "\nctrlKey=" + e.ctrlKey );
>> };
> 
> I notice that you put a "var" before the "e". Is that really necessary?

No.  As ā€œeā€ is in the formal parameter list, it is treated as as if it was a 
local variable.  Redeclaring a local variable has no effect.  Initializing 
it like that also has not.

A local variable can come in handy if the original value of the argument of 
the function call is needed later.  The local variable SHOULD have a 
different identifier then (otherwise it would prevent accesses to the 
argument value by parameter name).  Only insofar development tools (like 
Eclipse JSDT) that warn about parameter assignment are useful here, because 
ECMAScript implementations support only call-by-value (references to objects 
are values; properties and variables cannot be referenced in terms of their 
memory locations): Accidental assignments to the parameter itself will not 
change a value in the calling execution contexts.

> With
> 
> 
> var e = "1";
> 
> function foo(e) {
>    window.alert(e);
> }
> 
> foo("2");
> 
> 
> wouldn't the alert display "2"?

No, it would.  However, the whole operation is bogus.  It should be at least

  if (!e) e = window.event;

so that the assignment only takes place when necessary.  Further feature 
tests are recommended, see jsx.dom.createEventListener() [1].

[1] <http://PointedEars.de/wsvn/JSX/trunk/dom/events.js>

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to detect key pressed plus mouse click, e.g., ctrl + left click "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2014-02-21 10:45 -0800
  Re: How to detect key pressed plus mouse click, e.g., ctrl + left click "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-02-21 20:04 +0100
    Re: How to detect key pressed plus mouse click, e.g., ctrl + left click "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2014-02-21 11:21 -0800
      Re: How to detect key pressed plus mouse click, e.g., ctrl + left click "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-02-21 20:32 +0100
        Re: How to detect key pressed plus mouse click, e.g., ctrl + left click "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2014-02-21 14:24 -0800
          Re: How to detect key pressed plus mouse click, e.g., ctrl + left click "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-02-22 00:31 +0100
            Re: How to detect key pressed plus mouse click, e.g., ctrl + left click "Joey@still_Learning.invalid" <Joey@still_Learning.invalid> - 2014-02-21 17:41 -0800
        Re: How to detect key pressed plus mouse click, e.g., ctrl + left click Andrew Poulos <ap_prog@hotmail.com> - 2014-02-22 12:48 +1100
          Re: How to detect key pressed plus mouse click, e.g., ctrl + left click "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-02-22 10:36 +0100
          Re: How to detect key pressed plus mouse click, e.g., ctrl + left click Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-22 10:54 +0100
            Re: How to detect key pressed plus mouse click, e.g., ctrl + left click "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-02-22 11:19 +0100
              Re: How to detect key pressed plus mouse click, e.g., ctrl + left click Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-22 11:27 +0100
                Re: How to detect key pressed plus mouse click, e.g., ctrl + left click "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-02-22 11:39 +0100
                Re: How to detect key pressed plus mouse click, e.g., ctrl + left click Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-22 12:50 +0100
                Re: How to detect key pressed plus mouse click, e.g., ctrl + left click Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-22 12:56 +0100
                Re: How to detect key pressed plus mouse click, e.g., ctrl + left click John Harris <niam@jghnorth.org.uk.invalid> - 2014-02-23 14:00 +0000
            Re: How to detect key pressed plus mouse click, e.g., ctrl + left click Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-23 23:48 +0100
              Re: How to detect key pressed plus mouse click, e.g., ctrl + left click Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2014-02-23 20:04 -0300
            Re: How to detect key pressed plus mouse click, e.g., ctrl + left click Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-02-23 23:39 +0100

csiph-web