3 ms·
Maybe this is a hot take, but the `key` API in the dom was a massive mistake. I've been writing JavaScript since the aughts and I've never managed to use it in
by bastawhiz 3y ago
Maybe this is a hot take, but the `key` API in the dom was a massive mistake. I've been writing JavaScript since the aughts and I've never managed to use it in a way where it didn't feel like a mistake. It's always issues like this, where certain keys don't have the value you expect. Or capitalization becomes an issue. Or modifier keys get in the way. Or god forbid your user has a keyboard with a weird layout or does chording and the API just completely gives up.
As ugly as the keyCode/which APIs are, they work. I've never had an issue with them.
- kps 3y ago`keyCode` are just raw Windows codes, which are a mess if you ever stray from Windows or US English. `VK_A` does not necessarily correspond to an ‘a’ and does not necessarily correspond to the same position as A on a US keyboard — in general there is nothing you can reliably say about it. `code` is useful for key positions, e.g. for WASD movement in a game. `key` is useful as the interpretation of a key, but primarily for non-text keys, since IMEs and virtual keyboards mean that text does not necessarily correspond directly to keys.