How to determine which "+" key was pressed?

I have a request to replicate the + key as a tab key when the plus key is pressed on the license plate side.

It seems that the plus key is above the letters where the shift key is required, and the plus key, in which the numbers are in the keyboard configuration, has a numeric number 43.

How to determine which key is pressed?

Update: I used this example: https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_event_key_keycode ", as indicated below, this was the wrong way to do this.

+4
source share
2 answers

. = 107, = 187

, :

$('#text').on('keydown', function (e) {
  $('label').text(e.which);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="text" />
<label></label>
Hide result

key (IE9 +), , , , :

$('#text').on('keydown', function (e) {
  if (e.key == '+')
    console.log('You typed a plus symbol!');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="text" />
<label></label>
Hide result
+6

. :

$(document).on("keydown", function(evt){
  switch (evt.keyCode){
    case 107:
      console.log("You pressed '+' on the number pad");
      break;
    case 187:
      console.log("You pressed SHIFT '+' on main keyboard");
      break;    
  }     
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Just click once over here to give the "document" focus and then press the + key(s)
Hide result
+1

Source: https://habr.com/ru/post/1682443/


All Articles