如何检测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