Capture key press without placing an input element on the page?

前端 未结 5 1680
时光说笑
时光说笑 2020-11-27 03:12

How to capture key press, e.g., Ctrl+Z, without placing an input element on the page in JavaScript? Seems that in IE, keypress and keyup events can only be bound to input el

5条回答
  •  醉酒成梦
    2020-11-27 04:05

    Code & detects ctrl+z

    document.onkeyup = function(e) {
      if(e.ctrlKey && e.keyCode == 90) {
        // ctrl+z pressed
      }
    }
    

提交回复
热议问题