// JavaScript Document

function Clavier () {
	
	// console.log('----- class.clavier.js');
	
	var HAUT                    = 38;
	var DROITE                 = 39;
	var BAS                    = 40;
	var GAUCHE                 = 37;
	var ESPACE                 = 32;
	var E_KEY                  = 69; // Key code for 'E'
	var T_KEY                  = 84; // Key code for 'T'

	// Key codes for all alphabet letters
	var A_KEY = 65;
	var B_KEY = 66;
	var C_KEY = 67;
	var D_KEY = 68;
	var E_KEY = 69;
	var F_KEY = 70;
	var G_KEY = 71;
	var H_KEY = 72;
	var I_KEY = 73;
	var J_KEY = 74;
	var K_KEY = 75;
	var L_KEY = 76;
	var M_KEY = 77;
	var N_KEY = 78;
	var O_KEY = 79;
	var P_KEY = 80;
	var Q_KEY = 81;
	var R_KEY = 82;
	var S_KEY = 83;
	var U_KEY = 85;
	var V_KEY = 86;
	var W_KEY = 87;
	var X_KEY = 88;
	var Y_KEY = 89;
	var Z_KEY = 90;
	
	var _touche                = this;
	_touche.press              = false;
	_touche.haut               = false;
	_touche.droite             = false;
	_touche.bas                = false;
	_touche.gauche             = false;
	_touche.espace             = false;
	_touche.e                  = false; // New property for 'E'
	_touche.t                  = false; // New property for 'T'
	_touche.a                  = false;
	_touche.b                  = false;
	_touche.c                  = false;
	_touche.d                  = false;
	_touche.f                  = false;
	_touche.g                  = false;
	_touche.h                  = false;
	_touche.i                  = false;
	_touche.j                  = false;
	_touche.k                  = false;
	_touche.l                  = false;
	_touche.m                  = false;
	_touche.n                  = false;
	_touche.o                  = false;
	_touche.p                  = false;
	_touche.q                  = false;
	_touche.r                  = false;
	_touche.s                  = false;
	_touche.u                  = false;
	_touche.v                  = false;
	_touche.w                  = false;
	_touche.x                  = false;
	_touche.y                  = false;
	_touche.z                  = false;
	
	var _evt                   = null;
	var _statut                = false;
	
	document.onkeydown = function (evt) {
		_evt = evt || window.event;
		// console.log('document.onkeydown ' + _evt.keyCode);
		touche(_evt.keyCode, _evt.type);
	};
	
	document.onkeyup = function (evt) {
		_evt = evt || window.event;
		touche(_evt.keyCode, _evt.type);
	};
	
	// METHODES
	
	function touche(code, statut) {
		
		_statut = false;
		if (statut == 'keydown') {
			_statut = true;
		};
		
		switch (code) {
			case HAUT :
				_touche.press = _statut;
				_touche.haut = _statut;
				break;
			case DROITE :
				_touche.press = _statut;
				_touche.droite = _statut;
				break;
			case BAS :
				_touche.press = _statut;
				_touche.bas = _statut;
				break;
			case GAUCHE :
				_touche.press = _statut;
				_touche.gauche = _statut;
				break;
			case ESPACE :
				_touche.press = _statut;
				_touche.espace = _statut;
				break;
			case E_KEY : // Handle 'E' key
				_touche.press = _statut;
				_touche.e = _statut;
				break;
			case T_KEY : // Handle 'T' key
				_touche.press = _statut;
				_touche.t = _statut;
				break;
			case A_KEY :
				_touche.press = _statut;
				_touche.a = _statut;
				break;
			case B_KEY :
				_touche.press = _statut;
				_touche.b = _statut;
				break;
			case C_KEY :
				_touche.press = _statut;
				_touche.c = _statut;
				break;
			case D_KEY :
				_touche.press = _statut;
				_touche.d = _statut;
				break;
			case F_KEY :
				_touche.press = _statut;
				_touche.f = _statut;
				break;
			case G_KEY :
				_touche.press = _statut;
				_touche.g = _statut;
				break;
			case H_KEY :
				_touche.press = _statut;
				_touche.h = _statut;
				break;
			case I_KEY :
				_touche.press = _statut;
				_touche.i = _statut;
				break;
			case J_KEY :
				_touche.press = _statut;
				_touche.j = _statut;
				break;
			case K_KEY :
				_touche.press = _statut;
				_touche.k = _statut;
				break;
			case L_KEY :
				_touche.press = _statut;
				_touche.l = _statut;
				break;
			case M_KEY :
				_touche.press = _statut;
				_touche.m = _statut;
				break;
			case N_KEY :
				_touche.press = _statut;
				_touche.n = _statut;
				break;
			case O_KEY :
				_touche.press = _statut;
				_touche.o = _statut;
				break;
			case P_KEY :
				_touche.press = _statut;
				_touche.p = _statut;
				break;
			case Q_KEY :
				_touche.press = _statut;
				_touche.q = _statut;
				break;
			case R_KEY :
				_touche.press = _statut;
				_touche.r = _statut;
				break;
			case S_KEY :
				_touche.press = _statut;
				_touche.s = _statut;
				break;
			case U_KEY :
				_touche.press = _statut;
				_touche.u = _statut;
				break;
			case V_KEY :
				_touche.press = _statut;
				_touche.v = _statut;
				break;
			case W_KEY :
				_touche.press = _statut;
				_touche.w = _statut;
				break;
			case X_KEY :
				_touche.press = _statut;
				_touche.x = _statut;
				break;
			case Y_KEY :
				_touche.press = _statut;
				_touche.y = _statut;
				break;
			case Z_KEY :
				_touche.press = _statut;
				_touche.z = _statut;
				break;
			default :
				break;
		};
	};

};
