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

后端 未结 6 1733
慢半拍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:08

    There is event.location property for left ctrl key it will be 1 for right one 2, you can check browser support on canIuse

    if (e.which == 17) {
       if (event.location == 1) {
          // left ctrl key
       } else if (event.location == 2) {
          // right ctrl key
       }
    }
    

提交回复
热议问题