Skip to content

Commit

Permalink
fix keycodes
Browse files Browse the repository at this point in the history
  • Loading branch information
TimBorowy committed May 6, 2019
1 parent a3a98f4 commit 4117da9
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions public/js/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,36 +123,40 @@ function getSelectedGame() {
return thirthMenu.children[counter]
}

function addColorToSelection(selection){
function addColorToSelection(selection) {
activeMenu[selection].classList.add("selection")
}

function removeColorFromSelection(selection){
function removeColorFromSelection(selection) {
activeMenu[selection].classList.remove("selection")
}

// Listening to the browser which key is pressed.
document.onkeypress = function (evt) {
evt = evt || window.event;
var charCode = evt.keyCode || evt.which;
document.onkeydown = function (event) {

var charCode = event.which;
var charStr = String.fromCharCode(charCode);

if (charCode == 54 || charCode == 187) {
// Move right
if (charCode == 39 || charCode == 68) {
selectNextElement();
}

if (charCode == 52 || charCode == 48) {
// Move left
if (charCode == 37 || charCode == 65) {
selectPreviousElement();
}

if (charCode == 53 || charCode == 189) {
// Move down
if (charCode == 40 || charCode == 83) {
if (menuCounter + 1 < menuIndex.length) {
cacheUpCounter();
selectNextMenu();
}
}

if (charCode == 50 || charCode == 56) {
// Move up
if (charCode == 38 || charCode == 87) {
if (menuCounter - 1 >= 0) {
cacheDownCounter();
selectPreviousMenu();
Expand Down

0 comments on commit 4117da9

Please sign in to comment.