How can I tell if an event comes from right Ctrl key?

后端 未结 6 1734
慢半拍i
慢半拍i 2020-12-11 06:37

I have an event listener in Javascript, I can tell whether a key event is Ctrl (e.keyCode == 17), but how can I know this Ctrl comes from the right one or left

6条回答
  •  青春惊慌失措
    2020-12-11 07:13

    I don't know if it was available when this was asked, but you can distinguish left- from right-ctrl, as well as alt and shift. You can now use the KeyboardEvent.DOM_KEY_LOCATION_* properties to make this distinction.

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

    Be aware though, I discovered that Chrome appears to have a defect in its implementation. See How can I distinguish left- and right- shift, ctrl, and alt keys onkeyup in Chrome with Javascript

提交回复
热议问题