Navigate through list using arrow keys? (JavaScript/JQ)

Since you didn’t really explain what you’re having trouble with, I just created a general solution. Hopefully this helps: var li = $(‘li’); var liSelected; $(window).keydown(function(e) { if(e.which === 40) { if(liSelected) { liSelected.removeClass(‘selected’); next = liSelected.next(); if(next.length > 0) { liSelected = next.addClass(‘selected’); } else { liSelected = li.eq(0).addClass(‘selected’); } } else { liSelected … Read more

Disable arrow key scrolling in users browser

Summary Simply prevent the default browser action: window.addEventListener(“keydown”, function(e) { if([“Space”,”ArrowUp”,”ArrowDown”,”ArrowLeft”,”ArrowRight”].indexOf(e.code) > -1) { e.preventDefault(); } }, false); If you need to support Internet Explorer or other older browsers, use e.keyCode instead of e.code, but keep in mind that keyCode is deprecated and you need to use actual codes instead of strings: // Deprecated code! … Read more

getch and arrow codes

By pressing one arrow key getch will push three values into the buffer: ‘\033’ ‘[‘ ‘A’, ‘B’, ‘C’ or ‘D’ So the code will be something like this: if (getch() == ‘\033’) { // if the first value is esc getch(); // skip the [ switch(getch()) { // the real value case ‘A’: // code … Read more