onkeyup 按键弹起
onkeypress 按键按下并弹起
onkeydown 按键按下时触发
- window.onkeydown =function(e){
- console.log(e)
- console.log(e.key)
- console.log(e.keyCode)
- console.log(e.ctrlKey)
- // e.key 获取点击的哪个字符
- // e.keyCode 获取点击字符的字符编码
- if(e.key == 'c' && e.ctrlKey){
- console.log('你按下了Ctrl + c')
- }
- if(e.keyCode == '83' && e.ctrlKey && e.shiftKey && e.altKey){
- console.log('你按下了 Ctrl + shift + alt + s')
- }
- }