What is the utf8 code for all four arrow keys (up down left right)?
I am learning node.js and I am trying to detect whenever these keys are being pressed.
He
A mix of Moezalez and user568109 answers worked for me:
var stdin = process.stdin;
// Don't set the rawMode to continue listening for other full length options.
stdin.resume();
stdin.setEncoding('utf8');
stdin.on('data', function(input) {
// Take out the new line character at the end
var option = input.substr(0, input.length - 1);
switch (option) {
case '\u001b[A':
// Up
break;
case '\u001b[B':
// Down
break;
case '\u001b[C':
// Right
break;
case '\u001b[D':
// Left
break;
case 'something_else':
// Perform what something_else does
break;
}
});