简体   繁体   中英

Capture Alt, Ctrl or Shift in Firefox

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. ;)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM