DEV Community

Arnav Bansal
Arnav Bansal

Posted on

1 1

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

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?

Top comments (1)

Collapse
 
ampersanda profile image
Ampersanda

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

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay