How to catch the keypress
See original GitHub issueHi, first of all, compliments for the module.
I’m using term.on( ‘key’) to get the user keyboard input, but when I press something like ARROW_UP it produces on screen this: ^[[A
and until I press enter the on(‘key’) callback is not fired… so, since I need to simulate the cursor moving when the user press arrow keys how can I do?
term.grabInput( );
term.on( 'key' , function( key , matches , data ) {
switch ( key )
{
case 'UP' : term.up( 1 ) ; break ;
case 'DOWN' : term.down( 1 ) ; break ;
case 'LEFT' : term.left( 1 ) ; break ;
case 'RIGHT' : term.right( 1 ) ; break ;
case 'CTRL_C' : process.exit() ; break ;
default:
// Echo anything else
term.noFormat(
Buffer.isBuffer( data.code ) ?
data.code :
String.fromCharCode( data.code )
) ;
break ;
}
});
The example code is from here: http://blog.soulserv.net and (for me) is not working as described… the arrow keys produces (on screen): ^[[A
, … and until I press enter the key event is not fired
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Capture key press without placing an input element on the ...
How to capture key press, e.g., Ctrl+Z, without placing an input element on the page in JavaScript? Seems that in IE, keypress and...
Read more >Catching and Responding to Keyboard Events in JavaScript
The keypress event is mostly triggered when you press down any printable character, and it's fired after the key down event. In fact,...
Read more >Element: keypress event - Web APIs | MDN
The keypress event is fired when a key that produces a character value is pressed down.
Read more >onkeypress Event - W3Schools
Note: The onkeypress event is not fired for all keys (e.g. ALT, CTRL, SHIFT, ESC) in all browsers. To detect only whether the...
Read more >How to catch .keypress() on body - jQuery Forum
Hello, How can you catch the keycode on the body tag? ... $(document).keypress(function(event) {; alert('Handler for .keypress() called.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Can you tell me which OS and terminal you are using? It looks like it does not support the raw mode. Windows?
@cronvel
with the terminal provided by Bitvise I can use editors like nano and vim via ssh, eventually I will try to use termios if I really need, but for now i’m just “playing” with the code so I don’t want to complicate my life too much.
I didn’t see the documentation in deep, sorry I should have checked before! Later today when I’ve time I’ll try to see if it works like you suggested many thanks!