Merge pull request #4 from ragekit/master

switch keycode to key for better i18n (work on azerty now)
This commit is contained in:
Лu Лinveгa 2016-11-18 07:05:12 -08:00 committed by GitHub
commit 3548bf21ab

View File

@ -1,11 +1,11 @@
function Keyboard() function Keyboard()
{ {
this.is_locked = false; this.is_locked = false;
this.cmd = function() this.cmd = function()
{ {
var val = commander.element_input.value; var val = commander.element_input.value;
if(val.indexOf(";") > 0){ if(val.indexOf(";") > 0){
var cmds = val.split(";"); var cmds = val.split(";");
var vals = []; var vals = [];
@ -19,7 +19,7 @@ function Keyboard()
return [val.split(" ")]; return [val.split(" ")];
} }
} }
this.lock = function() this.lock = function()
{ {
this.is_locked = true; this.is_locked = true;
@ -35,21 +35,21 @@ function Keyboard()
this.listen = function(event) this.listen = function(event)
{ {
if(this.is_locked === true){ return; } if(this.is_locked === true){ return; }
switch (event.keyCode) if(event.keyCode == 9) this.key_tab();
{ switch (event.key) {
case 9: this.key_tab(); break; case "Enter": this.key_enter(); break;
case 13: this.key_enter(); break; case " " : this.key_space(); break;
case 32: this.key_space(); break; case "ArrowUp": this.key_arrow_up(); break;
case 38: this.key_arrow_up(); break; case "ArrowDown": this.key_arrow_down(); break;
case 40: this.key_arrow_down(); break; case "ArrowLeft": this.key_arrow_left(); break;
case 37: this.key_arrow_left(); break; case "ArrowRight": this.key_arrow_right(); break;
case 39: this.key_arrow_right(); break; case ":": this.key_colon(); break;
case 186: this.key_colon(); break; //not sure if this one needed anymore
case 190: if (event.shiftKey) this.key_colon(); break; case ";": if (event.shiftKey) this.key_colon(); break;
case 27: this.key_escape(); break; case "Escape": this.key_escape(); break;
} }
// Passive // Passive
var cmd = commander.element_input.value; var cmd = commander.element_input.value;
commander.passive(cmd.split(" ")); commander.passive(cmd.split(" "));
@ -63,7 +63,7 @@ function Keyboard()
this.key_enter = function() this.key_enter = function()
{ {
var cmd = commander.element_input.value; var cmd = commander.element_input.value;
if(cmd.indexOf(";") > 0){ if(cmd.indexOf(";") > 0){
var multi = cmd.split(";"); var multi = cmd.split(";");
var i = 0; var i = 0;
@ -99,13 +99,13 @@ function Keyboard()
this.key_arrow_right = function() this.key_arrow_right = function()
{ {
} }
this.key_colon = function() this.key_colon = function()
{ {
commander.show(); commander.show();
return false; return false;
} }
this.key_escape = function() this.key_escape = function()
{ {
commander.hide(); commander.hide();