DEV Community


How do I detect if the '+' key is pressed (without the shift)

Arnav Bansal
I slay dragons—or take them as pets.
・1 min read

I want to trigger the KeyboardEvent for the '+' key even if the '=' key is pressed

'shift+=' is '+' on English keyboards, but on other keyboards, the key for which 'shift+key' is '+' might be different. How do I account for all such cases?

Discussion (1)

ampersanda profile image

when keydown and some other events, an event has key property that has name of your keyboard key button.

input.addEventListener('keydown', function(e) {
  if (e.key === '+') {
    // ... do your code