Skip to content

Instantly share code, notes, and snippets.

@mappum
Created April 27, 2012 04:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mappum/2505802 to your computer and use it in GitHub Desktop.
Save mappum/2505802 to your computer and use it in GitHub Desktop.
function keyEvent(key) {
if(keyInterrupts) {
cpu.interrupt();
}
};
$(document).keydown(function(e) {
if(cpu.running && e.target.nodeName !== 'INPUT' && e.target.nodeName !== 'TEXTAREA') {
var key = keyMap[e.which] || e.which;
keysDown[key] = true;
keyEvent(key);
e.stopPropagation();
}
});
$(document).keyup(function(e) {
if(cpu.running && e.target.nodeName !== 'INPUT' && e.target.nodeName !== 'TEXTAREA') {
var key = keyMap[e.which] || e.which;
keysDown[key] = false;
keyEvent(key);
e.stopPropagation();
}
});
$(document).keypress(function(e) {
if(cpu.running && e.target.nodeName !== 'INPUT' && e.target.nodeName !== 'TEXTAREA') {
var key = keyMap[e.which] || e.which;
if(key <= 0x7f) {
keyboardBuffer.push(key);
}
keyEvent(key);
e.stopPropagation();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment