Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose KeyboardEvent.code on jQuery event #3978

waffledonkey opened this Issue Feb 14, 2018 · 3 comments


None yet
4 participants
Copy link

commented Feb 14, 2018


Keyboard events introduce new properties, .key and .code. The latter being especially useful because it normalizes keyboard layouts (eg. Dvorak) and different locales.


If you register a keydown event listener using W3 addEventListener and then console.log the event, the code property is present. If, however, you do the same thing using jQuery the code property is absent (presumably removed) -- but the key property is curiously present.

document.addEventListener('keydown', function (e) {
    console.log('W3:', e.type, e.code, e.key, e.keyCode);

$(document).on('keydown', function (e) {
    console.log('jQuery:', e.type, e.code, e.key, e.keyCode);


jQuery: keydown undefined ArrowRight 39
W3: keydown ArrowRight ArrowRight 39

Link to test case


While you're in there, IE implemented an older spec so they use 'Left', 'Right', 'Up' and 'Down' versus 'ArrowLeft', 'ArrowRight', 'ArrowUp' and 'ArrowDown' -- there may be other differences... If you still consider yourself an abstraction library I would LOVE if you could help pull IE up the hill.


This comment has been minimized.

Copy link

commented Feb 14, 2018

Agreed and I am thinking this is a typo because we have char and key but not code. I don't even see a char listed anywhere in the specs? @jbedard do you know? It's been around since jQuery 1.7 so it's not recent. I know the specs have changed several times over the years (which, keyCode/charCode, key/char).

The problem with trying to normalize the names in IE11 is that it is especially bloating to put a comprehensive mapping like that in jQuery. If every person who ever used jQuery needed it that might make sense, but very few people need more than one or two keys.

I should also mention that you can get this property in event.originalEvent.code as with all the raw properties.

@timmywil timmywil changed the title KeyboardEvent.code is eaten by jQuery Expose KeyboardEvent.code on jQuery event Feb 14, 2018

@timmywil timmywil added the Feature label Feb 14, 2018


This comment has been minimized.

Copy link

commented Feb 14, 2018

I don't think jQuery ever supported it by default. If it is a standard property then we should add it to the list.


This comment has been minimized.

Copy link

commented Feb 15, 2018

@dmethvin dmethvin closed this in 899c56f Apr 17, 2018

@GulajavaMinistudio GulajavaMinistudio referenced this issue Apr 19, 2018


Update upstream #45

0 of 4 tasks complete

@lock lock bot locked as resolved and limited conversation to collaborators Oct 14, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.