Can javascript tell the difference between left and right shift key?

In newer browsers supporting DOM3 you can use event.location to check the location.

In the DOM3 spec, there are 4 constants defined for location, DOM_KEY_LOCATION_STANDARD, DOM_KEY_LOCATION_LEFT, DOM_KEY_LOCATION_RIGHT, andDOM_KEY_LOCATION_NUMPAD.

In this case, you can do:

if (event.location === KeyboardEvent.DOM_KEY_LOCATION_LEFT){

} else if (event.location === KeyboardEvent.DOM_KEY_LOCATION_RIGHT){

}

Leave a Comment