myKeyboard = function(){
var self = this;
this.keyspressed = [];
this.i = [[0]];
document.onkeydown = function(event){
self.keyPress(event);
};
document.onkeyup = function(event){
self.keyUp(event);
};
};
myKeyboard.prototype.keyPress = function(event){
var code;
if (event.keyCode === [[0]] || event.keyCode == "undefined"){
code = event.charCode;
} else {
code = event.keyCode;
}
this.keyspressed = [[1]];
};
myKeyboard.prototype.keyUp = function(event){
var code;
if (event.keyCode === [[0]] || event.keyCode == "undefined"){
code = event.charCode;
} else {
code = event.keyCode;
}
this.keyspressed = [[0]];
};
myKeyboard.prototype.isKeyDown = function(/*int*/ keyCode){
if (typeof this.keyspressed[keyCode] == "undefined" || this.keyspressed[keyCode] === [[0]]){
return false;
} else {
return true;
}
};
[web] Javascript Question (Solved)
I've been playing around with javascript for the last few days and I've run into an issue with IE. I'm trying to capture the keyboard state using the following code:
This code works fine in Firefox, Safari, and Opera, but it fails in IE. I did some testing and "event" isn't being passed to the keyPress and keyUp functions.
Edit: fixed source tags.
[Edited by - Avictus on July 27, 2008 11:43:44 PM]
I'm not sure, but I have a hunch that the this keyword does not represent the right object in IE. I'm trying to find reference material to support my suspicion, but I can't find it right now :(
in IE, event is not defined. you should always use
event = event || window.event
to work cross browers.
event = event || window.event
to work cross browers.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement