KeyboardEvent.location returns nothing

I have thing piece of code:

$('body').on('keydown', function(e) {
    console.log(e.location)
});

It looks like e.location returns nothing, "undefined" appears at console. Basic task was to detect when left shift is pressed and when right one. I went to google and found this, but it doesn't work for me. Any suggestions?

Answers


I believe what you want is e.originalEvent.location - I was doing some snooping around the e object and found this:

Right Shift:

altKey: false
bubbles: true
cancelable: true
char: undefined
charCode: 0
ctrlKey: false
currentTarget: body
data: undefined
delegateTarget: body
eventPhase: 2
handleObj: Object
isDefaultPrevented: returnFalse()
jQuery21406245628797914833: true
key: undefined
keyCode: 16
metaKey: false
originalEvent: KeyboardEvent
  altKey: false
  bubbles: true
  cancelBubble: false
  cancelable: true
  charCode: 0
  ctrlKey: false
  currentTarget: null
  defaultPrevented: false
  detail: 0
  eventPhase: 0
  isTrusted: true
  isTrusted: true
  keyCode: 16
  keyIdentifier: "Shift"
  keyLocation: 2
  location: 2         // <---------------------

Left Shift

altKey: false
bubbles: true
cancelable: true
char: undefined
charCode: 0
ctrlKey: false
currentTarget: body
data: undefined
delegateTarget: body
eventPhase: 2
handleObj: Object
isDefaultPrevented: returnFalse()
jQuery21406245628797914833: true
key: undefined
keyCode: 16
metaKey: false
originalEvent: KeyboardEvent
  altKey: false
  bubbles: true
  cancelBubble: false
  cancelable: true
  charCode: 0
  ctrlKey: false
  currentTarget: null
  defaultPrevented: false
  detail: 0
  eventPhase: 0
  isTrusted: true
  isTrusted: true
  keyCode: 16
  keyIdentifier: "Shift"
  keyLocation: 2
  location: 1         // <---------------------

Using this, you can tell which shift key is pressed since left shift has an origanalEvent.location of 1 and right shift has an origanalEvent.location of 2 and it seems like any other key has an origanalEvent.location of 0.


Need Your Help

open a terminal from python

python terminal

I'm developing a program that has a button. When pressed, I want to open a terminal that runs:

Disabling any HTML put inside textarea and input

php html textarea

I have a textarea which then posts to a database (using PHP and MySQL) but I'd like to be able to disable any HTML, JS etc that's put inside the textarea. The main purpose is to stop people posting...