function key events

This commit is contained in:
overflowerror 2013-07-20 21:32:02 +02:00
parent 1d9bac087f
commit 8fb7da7044
2 changed files with 22 additions and 11 deletions

View file

@ -58,9 +58,11 @@ Emulator.addEventHandlers = function() {
console.log("Emulator: adding unfocus-event");
this.input.onblur = this.refocus;
console.log("Emulator: adding key-press-event");
this.input.onkeypress = this.handleKeyPress;
//this.input.onkeypress = this.handleKeyPress;
window.onkeypress = this.handleKeyPress;
console.log("Emulator: adding key-down-event");
this.input.onkeydown = this.handleKeyDown;
//this.input.onkeydown = this.handleKeyDown;
window.onkeydown = this.handleKeyDown;
var timerid = window.setInterval(function() {/*for (var i = 0; i < 10; i++)*/ Emulator.tick(0);}, 1);
Emulator.mainTickId = timerid;
console.log("Emulator: adding default 1ms (or cheated 0.1 ms) tick with tid=" + timerid);

View file

@ -4,17 +4,26 @@ KeyCodes.normalKey = function(code) {
return String.fromCharCode(code);
}
KeyCodes.isBackspace = function(code) {
if (code == 8)
return true;
return false;
return (code == 8);
}
KeyCodes.isDelete = function(code) {
if (code == 46)
return true;
return false;
return (code == 46);
}
KeyCodes.isEnter = function(code) {
if (code == 13)
return true;
return false;
return (code == 13);
}
KeyCodes.isEscape = function(code) {
return (code == 27);
}
KeyCodes.isLeft = function(code) {
return (code == 37);
}
KeyCodes.isUp = function(code) {
return (code == 38);
}
KeyCodes.isRight = function(code) {
return (code == 39);
}
KeyCodes.isDown = function(code) {
return (code == 40);
}