0

I'm using the below code to check whether the user have pressed the 'shift' key. It returns 16 correctly, since its the keycode for 'shift'.

But is there any way we can detect whether the pressed shift is the left or right one in the keyboard?

Here is the code I've used:

$(document).keydown(function (e) {
    if (e.keyCode == 16) {
        alert(e.which + " or Shift was pressed");
    }
});
Matt Way
  • 32,319
  • 10
  • 79
  • 85
Gijo Varghese
  • 11,264
  • 22
  • 73
  • 122

1 Answers1

2

For JQuery in particular, if you just look at your event e you will find

e.originalEvent.code

Which contains shiftLeft or shiftRight depending.

I'd guess originalEvent is actually the base javascript keypress event you could get from something like

body.onkeydown = function (e) { console.log(e); }

since it looks identical.

crackpotHouseplant
  • 380
  • 1
  • 3
  • 12