Detect CTRL and SHIFT key without keydown event?

后端 未结 1 1701
伪装坚强ぢ
伪装坚强ぢ 2020-12-11 03:45

I\'ve been wondering if I can detect CTRL and SHIFT key being pressed WITHOUT using keydown event.

The reason is that I am creating some sort o

相关标签:
1条回答
  • 2020-12-11 04:04

    You don't need any key events at all to detect Shift, Ctrl and Alt when mouse is clickedMDN.

    The Event object contains this information:

    element.addEventListener('click', function (e) {
        console.log(e.shiftKey);
        console.log(e.ctrlKey);
        console.log(e.altKey);
    });
    

    A demo at jsFiddle.

    These properties can be read also in keyboard event handlers.

    0 讨论(0)
提交回复
热议问题