0

Why the windows keycode doesn't work in this superscript code (on edge chromium with Tampermonkey)?

(function () {
    document.addEventListener('keydown', function (e) {
        //  67=C  91=windows key (or metaKey)    https://keycode.info/

        if (e.keyCode == 67 && e.keyCode == 91) {

            alert('detected')


        }
    }, false);
})();

I tried several letters with the windows key and using e.metaKey but without success.


ps: this not a duplicate of Can all keycode events be recognized by a user-script Jquery because I don't use keypress

JinSnow
  • 1,553
  • 4
  • 27
  • 49
  • 1
    `Win` shortcuts are handled by OS so the browser doesn't even see them. You can use a separate utility like AutoHotKey, AutoIt, and so on. – wOxxOm May 14 '20 at 07:32
  • 1
    Also note that `x == 67 && x == 91` is an impossible condition which will never be true. In general you need `e.metaKey && e.code == 'KeyC'`, use http://keycode.info/ for the actual values. – wOxxOm May 14 '20 at 08:25
  • thanks a lot I understand now that `x == 67 && x == 91 is an impossible condition`. But if `the browser doesn't see [the win key]` why 1) https://keycode.info/ sees it? 2) why `e.metaKey` works (when used alone ― it doesn't work in combination with another letter) ? – JinSnow May 14 '20 at 09:14
  • 1
    1) Only some `Win` keys are handled by OS, not all. 2) Depends on the letter. – wOxxOm May 14 '20 at 09:20
  • if you copy past your comment in an answer, I will select it. – JinSnow May 14 '20 at 09:23
  • this answer backs up your point: https://stackoverflow.com/a/6246851/1486850 – JinSnow May 14 '20 at 10:03

0 Answers0