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


Groups > comp.lang.javascript > #36177

Re: How to check if a key is currently down ...

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: How to check if a key is currently down ...
Date 2019-03-26 18:29 +0100
Organization PointedEars Software (PES)
Message-ID <340f6105-cc78-29e1-11ec-252126379941@PointedEars.de> (permalink)
References (1 earlier) <14dc5q8q828ot$.egjb1au5kypn.dlg@40tude.net> <4401b01e-8b83-3bfe-73be-ca0757c98d80@PointedEars.de> <slrnq9kjqu.6qm.jon+usenet@sable.unequivocal.eu> <011e45b6-1925-8b27-94c4-7aafc5094b5f@PointedEars.de> <slrnq9klu7.6qm.jon+usenet@sable.unequivocal.eu>

Show all headers | View raw


Jon Ribbens wrote:
> On 2019-03-26, Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
>> However, the previous answer is still wrong because there is nothing that
>> says that keyboard events are not fired or cannot be handled while “a
>> webpage is being loaded”.  So that is worth a try.
>>
>> Proof of concept:
>>
>> var w = window.open('', 'foo', 'width=400,height=400');
>> w.document.open();
>> w.document.write('<!doctype html><html><head><title>Shift key
>> status</title></head><body onkeydown="this.textContent = event.shiftKey;"
>> onkeyup="this.textContent = event.shiftKey;"></body>');
>> w.document.close();
>>
>> Press down the Shift key immediately after you execute that code (in the
>> Console).  You should see “true” in the popup when it has loaded.
>> [window.open() cannot be triggered in a window.setTimeout() callback if such
>> popups that are not directly initiated by the user are blocked.]
> 
> It doesn't work in Chrome for me; if I manage to press 'shift' quick
> enough before the window opens then the window remains blank. 

YMMV.

> And in fact if I copy'n'paste the code into the JavaScript console then
> setTimeout does work to open the window after a delay

Yes, AISB, window.open() does not work *if* such popups are blocked.

> and it's easy to verify that the events don't fire until the key status
> changes after the window has loaded.)

YMMV.  "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/57.0.2987.98 Safari/537.36", with several extensions, here.

-- 
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 check if a key is currently down ... "R.Wieser" <address@not.available> - 2019-03-25 08:23 +0100
  Re: How to check if a key is currently down ... Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-25 02:33 -0700
    Re: How to check if a key is currently down ... "R.Wieser" <address@not.available> - 2019-03-25 11:48 +0100
  Re: How to check if a key is currently down ... Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-03-25 02:39 -0700
  Re: How to check if a key is currently down ... Julio Di Egidio <julio@diegidio.name> - 2019-03-25 04:08 -0700
  Re: How to check if a key is currently down ... JJ <jj4public@vfemail.net> - 2019-03-25 19:42 +0700
    Re: How to check if a key is currently down ... "R.Wieser" <address@not.available> - 2019-03-25 17:21 +0100
    Re: How to check if a key is currently down ... Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-03-26 17:09 +0100
      Re: How to check if a key is currently down ... Jon Ribbens <jon+usenet@unequivocal.eu> - 2019-03-26 16:12 +0000
        Re: How to check if a key is currently down ... Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-03-26 17:35 +0100
          Re: How to check if a key is currently down ... Jon Ribbens <jon+usenet@unequivocal.eu> - 2019-03-26 16:48 +0000
            Re: How to check if a key is currently down ... Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-03-26 18:29 +0100
              Re: How to check if a key is currently down ... Jon Ribbens <jon+usenet@unequivocal.eu> - 2019-03-26 17:36 +0000
    Re: How to check if a key is currently down ... Julio Di Egidio <julio@diegidio.name> - 2019-03-26 18:23 -0700
  Re: How to check if a key is currently down ... Peter Büttner <not_for_mail_peb@gmx.net> - 2019-03-25 18:46 +0100
    Re: How to check if a key is currently down ... "R.Wieser" <address@not.available> - 2019-03-25 19:23 +0100
      Re: How to check if a key is currently down ... Peter Büttner <not_for_mail_peb@gmx.net> - 2019-03-27 19:26 +0100
        Re: How to check if a key is currently down ... "R.Wieser" <address@not.available> - 2019-04-05 09:23 +0200
          Re: How to check if a key is currently down ... Peter Büttner <not_for_mail_peb@gmx.net> - 2019-04-07 19:53 +0200

csiph-web