1

Using Firefox I do not find a way to capture keyboard events with JavaScript for Alt, Ctrl or Shift keys. It works on Chrome, Midori, SeaMonkey but not on Firefox.

Minimal reproducible example:

window.onkeydown = event => console.log(event);

I push AltLeft key and on Chrome I get:

KeyboardEvent {isTrusted: true, key: "Alt", code: "AltLeft"...

On Midori 1.1.4:

KeyboardEvent {isTrusted: true, key: "Alt", code: "AltLeft"...

Basilisk (~ old Mozilla) 2021.02.06:

keydown Alt { target: <body>, key: "Alt", charCode: 0, keyCode: 18 }

SeaMonkey 2.53.6 (x64):

keydown Alt { target: <body>, key: "Alt", charCode: 0, keyCode: 18 }

Firefox 86.0 (x64):


... nothing. Same with Ctrl and Shift keys.

Microsoft Windows [Version 10.0.17763.1757]

Thanks in advance!

PS: Mentioning of IE doesn't even worth. ;)

2 Answers2

0

I've tested this in FireFox 86.0 and it works as expected.

keydown Shift { target: body.activity-stream, key: "Shift", charCode: 0, keyCode: 16 }

keydown Control { target: body.activity-stream, key: "Control", charCode: 0, keyCode: 17 }

keydown Alt { target: body.activity-stream, key: "Alt", charCode: 0, keyCode: 18 }

Please check your environment and provide further information to assist in debugging.

StewartR
  • 141
  • 6
  • Microsoft Windows [Version 10.0.17763.1757] –  Mar 03 '21 at 09:17
  • Check it's not some plugin in your Firefox that is trying to prevent keylogging. – StewartR Mar 03 '21 at 09:51
  • I've tried in SaveMode - no difference. Alt, Ctrl and Shift are not captured. https://support.mozilla.org/en-US/kb/troubleshoot-firefox-issues-using-safe-mode –  Mar 03 '21 at 10:17
  • To confirm: does it log other keys, but just not shift, alt and ctrl? – StewartR Mar 03 '21 at 10:42
  • Yes. It logs all keys except Alt, Ctrl and Shift. Only in Firefox. –  Mar 03 '21 at 11:05
  • Have you tried this on another computer and get same result? It has to be something local to your machine, or something else in your code that isn't shared here. Can you provide more context how this is intended to be used in your code? Is it inside an input/textarea? – StewartR Mar 03 '21 at 12:38
0

I just had this exact same problem. After some googling I found the answer Firefox not detecting Alt key on keydown

Turns out that it was due to the fact that I have about:config privacy.resistFingerprinting set to true. Turning it off solved the problem for me.

tst
  • 479
  • 4
  • 7