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


Groups > comp.lang.javascript > #30740

Re: Interrogation of Shift-Key state

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Interrogation of Shift-Key state
Date 2016-06-25 22:33 +0200
Organization PointedEars Software (PES)
Message-ID <1772276.oMNUckLgyt@PointedEars.de> (permalink)
References <nklv6p$eap$1@gioia.aioe.org> <9a42c75f-3239-4a70-9ce3-7434db0edd00@googlegroups.com> <nkmg47$1b8k$2@gioia.aioe.org> <1652837.7Z3S40VBb9@PointedEars.de> <nkmlab$1k5j$1@gioia.aioe.org>

Show all headers | View raw


Janis Papanagnou wrote:

> On 25.06.2016 20:17, Thomas 'PointedEars' Lahn wrote:
>> Why do you want to avoid using the keydown/keyup events?
> 
> The samples I saw seemed to have suggested to have to install event
> handler functions, "addEventListener()",

EventTarget::addEventListener() is the DOM method that allows you to *add* 
event _listeners_ for an event to an object; it is available on all objects 
that implement the EventTarget interface.  You do not have to use it if the 
markup language, as in the case of HTML5, provides event-handler attributes 
(like “onclick”), or if the DOM implementation, as in the case of all of 
them (AFAIK), provides short-hand properties (like “.onclick”).

But it has the advantage – despite the possibility of user-defined wrappers 
that can do the same – of being able to add *more than one event listener 
for an event* to the same object.

You may want to use it if you are sure that all target environments support 
it for an event target, and if you want to use event bubbling or separate 
script code from markup; for example, it is a good idea if you need the same 
*complex* functionality in several documents because if anything changes in 
the functionality, you only need to change it in one place in the script, 
not in the markup (the markup then only says, e.g. by means of the “class” 
attribute, on which elements the functionality should be available).

> which would be bulky.

What is that supposed to mean?

> (There is also an aspect why events *might* not be appropriate in my 
> case; please see below for details on "state" vs. "event" in my case.)

Events are appropriate in your case and the only way to solve your problem.
With user interaction in a Web browser at least, you (have to) use event-
driven programming.

>> You need to use the keyboard event object that the runtime environment
>> creates for you, and dispatches to your event listener, instead.
> 
> This is obviously what I don't understand. Which one is it?

Pardon?

> The function I want to implement is the following; I press the 'shift' key
> (the event is irrelevant _at that stage_), and then I click a button.
> There's a onclick function associated with that button,

What you call “a onclick function” is an event listener for the “click” 
event on that button to which applies what I said before.

> and in that function I want to interrogate the *state* of the 'shift' key
> (where the 'shift'-pressed event is long gone; unless I have installed a 
> handler and memorized the 'shift' keypress-event).

Apparently you have not realized yet that the “shiftKey” property is not 
only available on keyboard events.  However, you would have *known* *had* 
*you* *tried* *it* *out*.  See also the FAQ on debugging.

>> <https://www.w3.org/TR/2015/REC-dom-20151119/#events>
> 
> Please be aware that posting links to standards is often not that helpful
> to non-experts as it is to experts;

In this case it is.  (You have not even read what I referred you to, have 
you?)

> the documents rely on knowledge that someone not familiar with many
> aspects of javascript just doesn't have.

There is no “javascript”, see the ECMAScript Support Matrix (URI in my sig).

> [rant]

<http://catb.org/esr/faqs/smart-questions.html>

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

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


Thread

Interrogation of Shift-Key state Janis Papanagnou <janis_papanagnou@hotmail.com> - 2016-06-25 14:59 +0200
  Re: Interrogation of Shift-Key state Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-06-25 17:18 +0200
    Re: Interrogation of Shift-Key state Janis Papanagnou <janis_papanagnou@hotmail.com> - 2016-06-25 19:47 +0200
      Re: Interrogation of Shift-Key state Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-06-25 20:07 +0200
  Re: Interrogation of Shift-Key state "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-25 08:51 -0700
    Re: Interrogation of Shift-Key state Janis Papanagnou <janis_papanagnou@hotmail.com> - 2016-06-25 19:47 +0200
      Re: Interrogation of Shift-Key state Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-06-25 20:17 +0200
        Re: Interrogation of Shift-Key state Janis Papanagnou <janis_papanagnou@hotmail.com> - 2016-06-25 21:16 +0200
          Re: Interrogation of Shift-Key state Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-06-25 22:33 +0200
            Re: Interrogation of Shift-Key state Janis Papanagnou <janis_papanagnou@hotmail.com> - 2016-06-26 00:49 +0200
              Re: Interrogation of Shift-Key state Tim Streater <timstreater@greenbee.net> - 2016-06-26 00:06 +0100
              Re: Interrogation of Shift-Key state Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-06-26 11:05 +0200
      Re: Interrogation of Shift-Key state "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-25 12:17 -0700
        Re: Interrogation of Shift-Key state "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-25 12:23 -0700
        Re: Interrogation of Shift-Key state Janis Papanagnou <janis_papanagnou@hotmail.com> - 2016-06-26 00:34 +0200
        Re: Interrogation of Shift-Key state Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-08-18 20:29 +0200
          Re: Interrogation of Shift-Key state "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-08-18 15:17 -0700
            Re: Interrogation of Shift-Key state Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-08-20 07:23 +0200
              Re: Interrogation of Shift-Key state "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-08-20 00:03 -0700
                Re: Interrogation of Shift-Key state Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-08-20 11:48 +0200
                Re: Interrogation of Shift-Key state "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-08-25 13:39 -0700
      Re: Interrogation of Shift-Key state "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-25 12:20 -0700
      Re: Interrogation of Shift-Key state Tim Streater <timstreater@greenbee.net> - 2016-06-25 22:33 +0100
        Re: Interrogation of Shift-Key state Janis Papanagnou <janis_papanagnou@hotmail.com> - 2016-06-26 01:18 +0200
          Re: Interrogation of Shift-Key state Tim Streater <timstreater@greenbee.net> - 2016-06-26 00:23 +0100
            Re: Interrogation of Shift-Key state Janis Papanagnou <janis_papanagnou@hotmail.com> - 2016-06-26 01:37 +0200
              Re: Interrogation of Shift-Key state Tim Streater <timstreater@greenbee.net> - 2016-06-26 09:41 +0100
  Re: Interrogation of Shift-Key state - workaround Janis Papanagnou <janis_papanagnou@hotmail.com> - 2016-06-26 00:33 +0200
    Re: Interrogation of Shift-Key state - workaround "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-06-26 00:53 +0200
      Re: Interrogation of Shift-Key state - workaround Janis Papanagnou <janis_papanagnou@hotmail.com> - 2016-06-26 01:31 +0200
        Re: Interrogation of Shift-Key state - workaround "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-25 16:52 -0700
        Re: Interrogation of Shift-Key state - workaround "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-06-26 01:56 +0200
    Re: Interrogation of Shift-Key state - workaround "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-06-25 16:50 -0700
  Re: Interrogation of Shift-Key state Joao Rodrigues <jr@none.com> - 2016-06-25 20:34 -0300

csiph-web