Fixes for keydown events

This commit is contained in:
Neale Pickett 2013-11-02 14:35:21 -06:00
parent 562ae7042f
commit 45845ab9ee
1 changed files with 364 additions and 337 deletions

View File

@ -357,21 +357,48 @@ function handle(event) {
function key(event) { function key(event) {
var e = event || window.event; var e = event || window.event;
var k = e.which || e.keyCode || 0;
var c; var c;
var newstate; var newstate;
switch (e.keyCode) { switch (k) {
case 32:
c = " ";
break;
case 38: case 38:
c = "up"; c = "up";
break; break;
case 40: case 40:
c = "down"; c = "down";
break; break;
case 188:
c = ",";
break;
case 190:
c = ".";
break;
case 221:
c = e.shiftKey ? "}" : "]";
break;
case 219:
c = e.shiftKey ? "{" : "[";
break;
default: default:
c = String.fromCharCode(e.which || e.keyCode || 0); if ((k >= 48) && (k <= 90)) {
c = String.fromCharCode(k);
if (! e.shiftKey) {
c = c.toLowerCase();
}
} else {
c = null;
}
break; break;
} }
bige = e;
console.log("Key " + k + " pressed: " + c + " === " + e.which);
switch (c) { switch (c) {
case "up": case "up":
if ((state == TIMEOUT) || (state == SETUP)) { if ((state == TIMEOUT) || (state == SETUP)) {
@ -439,7 +466,7 @@ function key(event) {
function save() { function save() {
chrome.storage.sync.set( chrome.storage.local.set(
{ {
"period_clock": e("period").remaining(), "period_clock": e("period").remaining(),
"name_a": e("name-a").innerHTML, "name_a": e("name-a").innerHTML,
@ -505,7 +532,7 @@ function start() {
startTimer(p); startTimer(p);
p.set(c); p.set(c);
} }
chrome.storage.sync.get(null, load); chrome.storage.local.get(null, load);
ei("jammer-a"); ei("jammer-a");
ei("jammer-b"); ei("jammer-b");
@ -519,7 +546,7 @@ function start() {
startTimer(j, window.tenths); startTimer(j, window.tenths);
j.set(120000); j.set(120000);
save_timer = setInterval(save, 1000); save_timer = setInterval(save, 10000); // Every 10 seconds
update_itimer = setInterval(update, 33); update_itimer = setInterval(update, 33);
} }