Vote count:
0
I wrote a function which should check if one particular button is being pressed. However, it seems to always return false. This is the function:
function keyPressed(ev) {
var r = false;
document.onkeypress = function(e) {
if (ev == e.which || ev == e.keyCode) {
r = true;
}
}
return r;
}
And this is how you'd call it:
if (keyPressed(119)) {
// do something
}
Checking with alert, they seem to be the same number when I press "W", but the function just always returns false. Are they different type?
asked 24 secs ago
JavaScript Keyboard events and comparison
Aucun commentaire:
Enregistrer un commentaire