Path: csiph.com!aioe.org!.POSTED!not-for-mail From: Janis Papanagnou Newsgroups: comp.lang.javascript Subject: Re: Interrogation of Shift-Key state Date: Sat, 25 Jun 2016 21:16:28 +0200 Organization: Aioe.org NNTP Server Lines: 66 Message-ID: References: <9a42c75f-3239-4a70-9ce3-7434db0edd00@googlegroups.com> <1652837.7Z3S40VBb9@PointedEars.de> NNTP-Posting-Host: MCXi+2dgmFPZdE43NmLC7g.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 X-Enigmail-Draft-Status: N1110 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.javascript:30735 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()", which would be bulky. (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.) > >> Or following the 'keyboardEvent()' link on the above 'keyboadEvent' link >> suggests using a KeyboardEvent() object. My naive tries on the latter >> (yes, I don't know much of these issues; else I wouldn't ask the question >> here), e.g. >> >> var x = new KeyboardEvent("keypress"); >> if (x.shiftKey) { >> alert("shift"); >> } else { >> alert("no shift"); >> } >> >> were ineffective, though, so more concrete input would be appreciated. > > You should read more carefully. With the above you *create* the keyboard > event object (and can simulate keypresses by dispatching it to elements). Okay. > > 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? 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, 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). To me it seems that the concept of an *event* handler would not be appropriate here (unless I memorize such events earlier, through an event listener); rather I wanted a simple *state* interrogation. From what has been posted thus far I cannot see whether it is possible at all to interrogate keyboard states. Or whether there's an event based approach that's as simple as I would have hoped there exists one. All I need is a boolean function, like keyboard.isShift(). > > Please be aware that posting links to standards is often not that helpful to non-experts as it is to experts; the documents rely on knowledge that someone not familiar with many aspects of javascript just doesn't have. In other words, they often result in yet more questions than the one asked. Also, spreading many technical terms like "W3C/WHATWG DOM" may show that you are an expert, but they don't help someone who is comming here to get information on a specific, small, and isolated question. Not everyone who is asking questions has the background of being proficient in Javascript, nor the goal become an expert. I'm, for example, while proficient in many aspects of Computer Science and IT, not targetting in getting a thorough understanding on Javascript. I just hope it is possible to get the piece of a jigsaw I need to solve the problem that is (still) an obstacle to me. Janis