如何檢測ctrl+q
使用JavaScript,這是我的代碼如何檢測CTRL + Q在JavaScript
<body>
<p id="x"></p>
<script>
window.onkeydown = function() {detect(event);}
window.onkeypress = function() {res(event);}
var act = false;
function detect(event) {
if(event.ctrlKey) {
act = true;
}
else
act = false;
}
function res(event) {
if(act) {
document.getElementById("x").innerHTML = "ctrl " + String.fromCharCode(event.which);
}
else
document.getElementById("x").innerHTML = String.fromCharCode(event.which);
}
</script>
</body>
我想只有JavaScript做。
這個問題已經被問:參見[如何找到的,出了什麼字符鍵,是壓(HTTP :?//stackoverflow.com/questions/1846599/how-to-find-out-what-character-key-is-pressed) –
@KevinWallis因此,我們將其標記:) – dbf